Fixed some linter issues

This commit is contained in:
klesomik 2020-04-05 15:07:09 +03:00
parent 78b5f88e4b
commit 5c3b08c369
5 changed files with 34 additions and 40 deletions

View file

@ -51,7 +51,7 @@ func main() {
for { for {
newKey := <-newKeys newKey := <-newKeys
if isBetter(currentBest[:], newKey.id[:]) || len(currentBest) == 0 { if isBetter(currentBest, newKey.id[:]) || len(currentBest) == 0 {
currentBest = newKey.id currentBest = newKey.id
for _, channel := range threadChannels { for _, channel := range threadChannels {
select { select {
@ -61,13 +61,13 @@ func main() {
fmt.Println("--------------------------------------------------------------------------------") fmt.Println("--------------------------------------------------------------------------------")
switch { switch {
case *doSig: case *doSig:
fmt.Println("sigPriv:", hex.EncodeToString(newKey.priv[:])) fmt.Println("sigPriv:", hex.EncodeToString(newKey.priv))
fmt.Println("sigPub:", hex.EncodeToString(newKey.pub[:])) fmt.Println("sigPub:", hex.EncodeToString(newKey.pub))
fmt.Println("TreeID:", hex.EncodeToString(newKey.id[:])) fmt.Println("TreeID:", hex.EncodeToString(newKey.id))
default: default:
fmt.Println("boxPriv:", hex.EncodeToString(newKey.priv[:])) fmt.Println("boxPriv:", hex.EncodeToString(newKey.priv))
fmt.Println("boxPub:", hex.EncodeToString(newKey.pub[:])) fmt.Println("boxPub:", hex.EncodeToString(newKey.pub))
fmt.Println("NodeID:", hex.EncodeToString(newKey.id[:])) fmt.Println("NodeID:", hex.EncodeToString(newKey.id))
fmt.Println("IP:", newKey.ip) fmt.Println("IP:", newKey.ip)
} }
} }
@ -76,12 +76,10 @@ func main() {
func isBetter(oldID, newID []byte) bool { func isBetter(oldID, newID []byte) bool {
for idx := range oldID { for idx := range oldID {
if newID[idx] > oldID[idx] { if newID[idx] == oldID[idx] {
return true continue
}
if newID[idx] < oldID[idx] {
return false
} }
return newID[idx] > oldID[idx]
} }
return false return false
} }

View file

@ -60,8 +60,8 @@ func readConfig(useconf *bool, useconffile *string, normaliseconf *bool) *config
// throwing everywhere when it's converting things into UTF-16 for the hell // throwing everywhere when it's converting things into UTF-16 for the hell
// of it - remove it and decode back down into UTF-8. This is necessary // of it - remove it and decode back down into UTF-8. This is necessary
// because hjson doesn't know what to do with UTF-16 and will panic // because hjson doesn't know what to do with UTF-16 and will panic
if bytes.Compare(conf[0:2], []byte{0xFF, 0xFE}) == 0 || if bytes.Equal(conf[0:2], []byte{0xFF, 0xFE}) ||
bytes.Compare(conf[0:2], []byte{0xFE, 0xFF}) == 0 { bytes.Equal(conf[0:2], []byte{0xFE, 0xFF}) {
utf := unicode.UTF16(unicode.BigEndian, unicode.UseBOM) utf := unicode.UTF16(unicode.BigEndian, unicode.UseBOM)
decoder := utf.NewDecoder() decoder := utf.NewDecoder()
conf, err = decoder.Bytes(conf) conf, err = decoder.Bytes(conf)
@ -222,7 +222,7 @@ func main() {
getNodeID := func() *crypto.NodeID { getNodeID := func() *crypto.NodeID {
if pubkey, err := hex.DecodeString(cfg.EncryptionPublicKey); err == nil { if pubkey, err := hex.DecodeString(cfg.EncryptionPublicKey); err == nil {
var box crypto.BoxPubKey var box crypto.BoxPubKey
copy(box[:], pubkey[:]) copy(box[:], pubkey)
return crypto.GetNodeID(&box) return crypto.GetNodeID(&box)
} }
return nil return nil

View file

@ -78,8 +78,8 @@ func run() int {
if *server == endpoint { if *server == endpoint {
if config, err := ioutil.ReadFile(defaults.GetDefaults().DefaultConfigFile); err == nil { if config, err := ioutil.ReadFile(defaults.GetDefaults().DefaultConfigFile); err == nil {
if bytes.Compare(config[0:2], []byte{0xFF, 0xFE}) == 0 || if bytes.Equal(config[0:2], []byte{0xFF, 0xFE}) ||
bytes.Compare(config[0:2], []byte{0xFE, 0xFF}) == 0 { bytes.Equal(config[0:2], []byte{0xFE, 0xFF}) {
utf := unicode.UTF16(unicode.BigEndian, unicode.UseBOM) utf := unicode.UTF16(unicode.BigEndian, unicode.UseBOM)
decoder := utf.NewDecoder() decoder := utf.NewDecoder()
config, err = decoder.Bytes(config) config, err = decoder.Bytes(config)

View file

@ -181,13 +181,12 @@ func (a *AdminSocket) SetupAdminHandlers(na *AdminSocket) {
in["uri"].(string), in["uri"].(string),
}, },
}, nil }, nil
} else {
return Info{
"not_added": []string{
in["uri"].(string),
},
}, errors.New("Failed to add peer")
} }
return Info{
"not_added": []string{
in["uri"].(string),
},
}, errors.New("Failed to add peer")
}) })
a.AddHandler("removePeer", []string{"port"}, func(in Info) (Info, error) { a.AddHandler("removePeer", []string{"port"}, func(in Info) (Info, error) {
port, err := strconv.ParseInt(fmt.Sprint(in["port"]), 10, 64) port, err := strconv.ParseInt(fmt.Sprint(in["port"]), 10, 64)
@ -200,13 +199,12 @@ func (a *AdminSocket) SetupAdminHandlers(na *AdminSocket) {
fmt.Sprint(port), fmt.Sprint(port),
}, },
}, nil }, nil
} else {
return Info{
"not_removed": []string{
fmt.Sprint(port),
},
}, errors.New("Failed to remove peer")
} }
return Info{
"not_removed": []string{
fmt.Sprint(port),
},
}, errors.New("Failed to remove peer")
}) })
a.AddHandler("getAllowedEncryptionPublicKeys", []string{}, func(in Info) (Info, error) { a.AddHandler("getAllowedEncryptionPublicKeys", []string{}, func(in Info) (Info, error) {
return Info{"allowed_box_pubs": a.core.GetAllowedEncryptionPublicKeys()}, nil return Info{"allowed_box_pubs": a.core.GetAllowedEncryptionPublicKeys()}, nil
@ -218,13 +216,12 @@ func (a *AdminSocket) SetupAdminHandlers(na *AdminSocket) {
in["box_pub_key"].(string), in["box_pub_key"].(string),
}, },
}, nil }, nil
} else {
return Info{
"not_added": []string{
in["box_pub_key"].(string),
},
}, errors.New("Failed to add allowed key")
} }
return Info{
"not_added": []string{
in["box_pub_key"].(string),
},
}, errors.New("Failed to add allowed key")
}) })
a.AddHandler("removeAllowedEncryptionPublicKey", []string{"box_pub_key"}, func(in Info) (Info, error) { a.AddHandler("removeAllowedEncryptionPublicKey", []string{"box_pub_key"}, func(in Info) (Info, error) {
if a.core.RemoveAllowedEncryptionPublicKey(in["box_pub_key"].(string)) == nil { if a.core.RemoveAllowedEncryptionPublicKey(in["box_pub_key"].(string)) == nil {
@ -250,10 +247,10 @@ func (a *AdminSocket) SetupAdminHandlers(na *AdminSocket) {
coords := util.DecodeCoordString(in["coords"].(string)) coords := util.DecodeCoordString(in["coords"].(string))
var boxPubKey crypto.BoxPubKey var boxPubKey crypto.BoxPubKey
if b, err := hex.DecodeString(in["box_pub_key"].(string)); err == nil { if b, err := hex.DecodeString(in["box_pub_key"].(string)); err == nil {
copy(boxPubKey[:], b[:]) copy(boxPubKey[:], b)
if n, err := hex.DecodeString(in["target"].(string)); err == nil { if n, err := hex.DecodeString(in["target"].(string)); err == nil {
var targetNodeID crypto.NodeID var targetNodeID crypto.NodeID
copy(targetNodeID[:], n[:]) copy(targetNodeID[:], n)
result, reserr = a.core.DHTPing(boxPubKey, coords, &targetNodeID) result, reserr = a.core.DHTPing(boxPubKey, coords, &targetNodeID)
} else { } else {
result, reserr = a.core.DHTPing(boxPubKey, coords, nil) result, reserr = a.core.DHTPing(boxPubKey, coords, nil)
@ -294,7 +291,7 @@ func (a *AdminSocket) SetupAdminHandlers(na *AdminSocket) {
return Info{}, errors.New("Expecting both box_pub_key and coords") return Info{}, errors.New("Expecting both box_pub_key and coords")
} else { } else {
if b, err := hex.DecodeString(in["box_pub_key"].(string)); err == nil { if b, err := hex.DecodeString(in["box_pub_key"].(string)); err == nil {
copy(boxPubKey[:], b[:]) copy(boxPubKey[:], b)
} else { } else {
return Info{}, err return Info{}, err
} }

View file

@ -30,9 +30,8 @@ func UnlockThread() {
func ResizeBytes(bs []byte, length int) []byte { func ResizeBytes(bs []byte, length int) []byte {
if cap(bs) >= length { if cap(bs) >= length {
return bs[:length] return bs[:length]
} else {
return make([]byte, length)
} }
return make([]byte, length)
} }
// TimerStop stops a timer and makes sure the channel is drained, returns true if the timer was stopped before firing. // TimerStop stops a timer and makes sure the channel is drained, returns true if the timer was stopped before firing.