mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-30 07:05:06 +03:00
Accept some linter suggestions
This commit is contained in:
parent
55f8c7c042
commit
57cad7eabc
12 changed files with 42 additions and 60 deletions
|
@ -328,9 +328,9 @@ func main() {
|
||||||
// deferred Stop function above will run which will shut down TUN/TAP.
|
// deferred Stop function above will run which will shut down TUN/TAP.
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case _ = <-c:
|
case <-c:
|
||||||
goto exit
|
goto exit
|
||||||
case _ = <-r:
|
case <-r:
|
||||||
if *useconffile != "" {
|
if *useconffile != "" {
|
||||||
cfg = readConfig(useconf, useconffile, normaliseconf)
|
cfg = readConfig(useconf, useconffile, normaliseconf)
|
||||||
logger.Infoln("Reloading configuration from", *useconffile)
|
logger.Infoln("Reloading configuration from", *useconffile)
|
||||||
|
|
|
@ -53,7 +53,7 @@ func (a *AdminSocket) AddHandler(name string, args []string, handlerfunc func(In
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// init runs the initial admin setup.
|
// Init runs the initial admin setup.
|
||||||
func (a *AdminSocket) Init(c *yggdrasil.Core, state *config.NodeState, log *log.Logger, options interface{}) error {
|
func (a *AdminSocket) Init(c *yggdrasil.Core, state *config.NodeState, log *log.Logger, options interface{}) error {
|
||||||
a.core = c
|
a.core = c
|
||||||
a.log = log
|
a.log = log
|
||||||
|
@ -230,13 +230,12 @@ func (a *AdminSocket) SetupAdminHandlers(na *AdminSocket) {
|
||||||
in["box_pub_key"].(string),
|
in["box_pub_key"].(string),
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
} else {
|
}
|
||||||
return Info{
|
return Info{
|
||||||
"not_removed": []string{
|
"not_removed": []string{
|
||||||
in["box_pub_key"].(string),
|
in["box_pub_key"].(string),
|
||||||
},
|
},
|
||||||
}, errors.New("Failed to remove allowed key")
|
}, errors.New("Failed to remove allowed key")
|
||||||
}
|
|
||||||
})
|
})
|
||||||
a.AddHandler("dhtPing", []string{"box_pub_key", "coords", "[target]"}, func(in Info) (Info, error) {
|
a.AddHandler("dhtPing", []string{"box_pub_key", "coords", "[target]"}, func(in Info) (Info, error) {
|
||||||
var reserr error
|
var reserr error
|
||||||
|
@ -284,9 +283,8 @@ func (a *AdminSocket) SetupAdminHandlers(na *AdminSocket) {
|
||||||
var jsoninfo interface{}
|
var jsoninfo interface{}
|
||||||
if err := json.Unmarshal(nodeinfo, &jsoninfo); err != nil {
|
if err := json.Unmarshal(nodeinfo, &jsoninfo); err != nil {
|
||||||
return Info{}, err
|
return Info{}, err
|
||||||
} else {
|
|
||||||
return Info{"nodeinfo": jsoninfo}, nil
|
|
||||||
}
|
}
|
||||||
|
return Info{"nodeinfo": jsoninfo}, nil
|
||||||
} else if in["box_pub_key"] == nil || in["coords"] == nil {
|
} else if in["box_pub_key"] == nil || in["coords"] == nil {
|
||||||
return Info{}, errors.New("Expecting both box_pub_key and coords")
|
return Info{}, errors.New("Expecting both box_pub_key and coords")
|
||||||
} else {
|
} else {
|
||||||
|
@ -302,12 +300,10 @@ func (a *AdminSocket) SetupAdminHandlers(na *AdminSocket) {
|
||||||
var m map[string]interface{}
|
var m map[string]interface{}
|
||||||
if err = json.Unmarshal(result, &m); err == nil {
|
if err = json.Unmarshal(result, &m); err == nil {
|
||||||
return Info{"nodeinfo": m}, nil
|
return Info{"nodeinfo": m}, nil
|
||||||
} else {
|
}
|
||||||
return Info{}, err
|
return Info{}, err
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return Info{}, err
|
return Info{}, err
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,9 +326,8 @@ func (a *AdminSocket) Stop() error {
|
||||||
if a.listener != nil {
|
if a.listener != nil {
|
||||||
a.started = false
|
a.started = false
|
||||||
return a.listener.Close()
|
return a.listener.Close()
|
||||||
} else {
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// listen is run by start and manages API connections.
|
// listen is run by start and manages API connections.
|
||||||
|
|
|
@ -272,7 +272,7 @@ func (n *BoxNonce) Increment() {
|
||||||
n[len(n)-1] += 2
|
n[len(n)-1] += 2
|
||||||
for i := len(n) - 2; i >= 0; i-- {
|
for i := len(n) - 2; i >= 0; i-- {
|
||||||
if n[i+1] < oldNonce[i+1] {
|
if n[i+1] < oldNonce[i+1] {
|
||||||
n[i] += 1
|
n[i]++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,16 +68,14 @@ func (t *TunAdapter) SetupAdminHandlers(a *admin.AdminSocket) {
|
||||||
a.AddHandler("addLocalSubnet", []string{"subnet"}, func(in admin.Info) (admin.Info, error) {
|
a.AddHandler("addLocalSubnet", []string{"subnet"}, func(in admin.Info) (admin.Info, error) {
|
||||||
if err := t.ckr.addLocalSubnet(in["subnet"].(string)); err == nil {
|
if err := t.ckr.addLocalSubnet(in["subnet"].(string)); err == nil {
|
||||||
return admin.Info{"added": []string{in["subnet"].(string)}}, nil
|
return admin.Info{"added": []string{in["subnet"].(string)}}, nil
|
||||||
} else {
|
|
||||||
return admin.Info{"not_added": []string{in["subnet"].(string)}}, errors.New("Failed to add source subnet")
|
|
||||||
}
|
}
|
||||||
|
return admin.Info{"not_added": []string{in["subnet"].(string)}}, errors.New("Failed to add source subnet")
|
||||||
})
|
})
|
||||||
a.AddHandler("addRemoteSubnet", []string{"subnet", "box_pub_key"}, func(in admin.Info) (admin.Info, error) {
|
a.AddHandler("addRemoteSubnet", []string{"subnet", "box_pub_key"}, func(in admin.Info) (admin.Info, error) {
|
||||||
if err := t.ckr.addRemoteSubnet(in["subnet"].(string), in["box_pub_key"].(string)); err == nil {
|
if err := t.ckr.addRemoteSubnet(in["subnet"].(string), in["box_pub_key"].(string)); err == nil {
|
||||||
return admin.Info{"added": []string{fmt.Sprintf("%s via %s", in["subnet"].(string), in["box_pub_key"].(string))}}, nil
|
return admin.Info{"added": []string{fmt.Sprintf("%s via %s", in["subnet"].(string), in["box_pub_key"].(string))}}, nil
|
||||||
} else {
|
|
||||||
return admin.Info{"not_added": []string{fmt.Sprintf("%s via %s", in["subnet"].(string), in["box_pub_key"].(string))}}, errors.New("Failed to add route")
|
|
||||||
}
|
}
|
||||||
|
return admin.Info{"not_added": []string{fmt.Sprintf("%s via %s", in["subnet"].(string), in["box_pub_key"].(string))}}, errors.New("Failed to add route")
|
||||||
})
|
})
|
||||||
a.AddHandler("getSourceSubnets", []string{}, func(in admin.Info) (admin.Info, error) {
|
a.AddHandler("getSourceSubnets", []string{}, func(in admin.Info) (admin.Info, error) {
|
||||||
var subnets []string
|
var subnets []string
|
||||||
|
@ -104,15 +102,13 @@ func (t *TunAdapter) SetupAdminHandlers(a *admin.AdminSocket) {
|
||||||
a.AddHandler("removeLocalSubnet", []string{"subnet"}, func(in admin.Info) (admin.Info, error) {
|
a.AddHandler("removeLocalSubnet", []string{"subnet"}, func(in admin.Info) (admin.Info, error) {
|
||||||
if err := t.ckr.removeLocalSubnet(in["subnet"].(string)); err == nil {
|
if err := t.ckr.removeLocalSubnet(in["subnet"].(string)); err == nil {
|
||||||
return admin.Info{"removed": []string{in["subnet"].(string)}}, nil
|
return admin.Info{"removed": []string{in["subnet"].(string)}}, nil
|
||||||
} else {
|
|
||||||
return admin.Info{"not_removed": []string{in["subnet"].(string)}}, errors.New("Failed to remove source subnet")
|
|
||||||
}
|
}
|
||||||
|
return admin.Info{"not_removed": []string{in["subnet"].(string)}}, errors.New("Failed to remove source subnet")
|
||||||
})
|
})
|
||||||
a.AddHandler("removeRemoteSubnet", []string{"subnet", "box_pub_key"}, func(in admin.Info) (admin.Info, error) {
|
a.AddHandler("removeRemoteSubnet", []string{"subnet", "box_pub_key"}, func(in admin.Info) (admin.Info, error) {
|
||||||
if err := t.ckr.removeRemoteSubnet(in["subnet"].(string), in["box_pub_key"].(string)); err == nil {
|
if err := t.ckr.removeRemoteSubnet(in["subnet"].(string), in["box_pub_key"].(string)); err == nil {
|
||||||
return admin.Info{"removed": []string{fmt.Sprintf("%s via %s", in["subnet"].(string), in["box_pub_key"].(string))}}, nil
|
return admin.Info{"removed": []string{fmt.Sprintf("%s via %s", in["subnet"].(string), in["box_pub_key"].(string))}}, nil
|
||||||
} else {
|
|
||||||
return admin.Info{"not_removed": []string{fmt.Sprintf("%s via %s", in["subnet"].(string), in["box_pub_key"].(string))}}, errors.New("Failed to remove route")
|
|
||||||
}
|
}
|
||||||
|
return admin.Info{"not_removed": []string{fmt.Sprintf("%s via %s", in["subnet"].(string), in["box_pub_key"].(string))}}, errors.New("Failed to remove route")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -199,7 +199,6 @@ func (tun *TunAdapter) _handlePacket(recvd []byte, err error) {
|
||||||
tc.writeFrom(nil, packet)
|
tc.writeFrom(nil, packet)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,12 +54,11 @@ func (c *cancellation) Cancel(err error) error {
|
||||||
defer c.mutex.Unlock()
|
defer c.mutex.Unlock()
|
||||||
if c.done {
|
if c.done {
|
||||||
return c.err
|
return c.err
|
||||||
} else {
|
}
|
||||||
c.err = err
|
c.err = err
|
||||||
c.done = true
|
c.done = true
|
||||||
close(c.cancel)
|
close(c.cancel)
|
||||||
return nil
|
return nil
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error returns the error provided to Cancel, or nil if no error has been provided.
|
// Error returns the error provided to Cancel, or nil if no error has been provided.
|
||||||
|
|
|
@ -166,10 +166,9 @@ func (c *Conn) _getDeadlineCancellation(t *time.Time) (util.Cancellation, bool)
|
||||||
// A deadline is set, so return a Cancellation that uses it
|
// A deadline is set, so return a Cancellation that uses it
|
||||||
c := util.CancellationWithDeadline(c.session.cancel, *t)
|
c := util.CancellationWithDeadline(c.session.cancel, *t)
|
||||||
return c, true
|
return c, true
|
||||||
} else {
|
}
|
||||||
// No deadline was set, so just return the existing cancellation and a dummy value
|
// No deadline was set, so just return the existing cancellation and a dummy value
|
||||||
return c.session.cancel, false
|
return c.session.cancel, false
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetReadCallback allows you to specify a function that will be called whenever
|
// SetReadCallback allows you to specify a function that will be called whenever
|
||||||
|
@ -224,9 +223,8 @@ func (c *Conn) readNoCopy() ([]byte, error) {
|
||||||
case <-cancel.Finished():
|
case <-cancel.Finished():
|
||||||
if cancel.Error() == util.CancellationTimeoutError {
|
if cancel.Error() == util.CancellationTimeoutError {
|
||||||
return nil, ConnError{errors.New("read timeout"), true, false, false, 0}
|
return nil, ConnError{errors.New("read timeout"), true, false, false, 0}
|
||||||
} else {
|
|
||||||
return nil, ConnError{errors.New("session closed"), false, false, true, 0}
|
|
||||||
}
|
}
|
||||||
|
return nil, ConnError{errors.New("session closed"), false, false, true, 0}
|
||||||
case bs := <-c.readBuffer:
|
case bs := <-c.readBuffer:
|
||||||
return bs, nil
|
return bs, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -203,7 +203,7 @@ func (intf *linkInterface) handler() error {
|
||||||
<-oldIntf.closed
|
<-oldIntf.closed
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
} else {
|
}
|
||||||
intf.closed = make(chan struct{})
|
intf.closed = make(chan struct{})
|
||||||
intf.link.interfaces[intf.info] = intf
|
intf.link.interfaces[intf.info] = intf
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -213,7 +213,6 @@ func (intf *linkInterface) handler() error {
|
||||||
close(intf.closed)
|
close(intf.closed)
|
||||||
}()
|
}()
|
||||||
intf.link.core.log.Debugln("DEBUG: registered interface for", intf.name)
|
intf.link.core.log.Debugln("DEBUG: registered interface for", intf.name)
|
||||||
}
|
|
||||||
intf.link.mutex.Unlock()
|
intf.link.mutex.Unlock()
|
||||||
// Create peer
|
// Create peer
|
||||||
shared := crypto.GetSharedKey(myLinkPriv, &meta.link)
|
shared := crypto.GetSharedKey(myLinkPriv, &meta.link)
|
||||||
|
|
|
@ -136,15 +136,15 @@ func (m *nodeinfo) _setNodeInfo(given interface{}, privacy bool) error {
|
||||||
newnodeinfo[key] = value
|
newnodeinfo[key] = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if newjson, err := json.Marshal(newnodeinfo); err == nil {
|
newjson, err := json.Marshal(newnodeinfo)
|
||||||
|
if err == nil {
|
||||||
if len(newjson) > 16384 {
|
if len(newjson) > 16384 {
|
||||||
return errors.New("NodeInfo exceeds max length of 16384 bytes")
|
return errors.New("NodeInfo exceeds max length of 16384 bytes")
|
||||||
}
|
}
|
||||||
m.myNodeInfo = newjson
|
m.myNodeInfo = newjson
|
||||||
return nil
|
return nil
|
||||||
} else {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add nodeinfo into the cache for a node
|
// Add nodeinfo into the cache for a node
|
||||||
|
|
|
@ -532,7 +532,6 @@ func (t *switchTable) unlockedHandleMsg(msg *switchMsg, fromPort switchPort, rep
|
||||||
if true || doUpdate {
|
if true || doUpdate {
|
||||||
t.updater.Store(&sync.Once{})
|
t.updater.Store(&sync.Once{})
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -615,9 +614,8 @@ func (t *switchTable) portIsCloser(dest []byte, port switchPort) bool {
|
||||||
theirDist := info.locator.dist(dest)
|
theirDist := info.locator.dist(dest)
|
||||||
myDist := table.self.dist(dest)
|
myDist := table.self.dist(dest)
|
||||||
return theirDist < myDist
|
return theirDist < myDist
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the coords of a packet without decoding
|
// Get the coords of a packet without decoding
|
||||||
|
|
|
@ -196,10 +196,9 @@ func (t *tcp) listener(l *TcpListener, listenaddr string) {
|
||||||
t.mutex.Unlock()
|
t.mutex.Unlock()
|
||||||
l.Listener.Close()
|
l.Listener.Close()
|
||||||
return
|
return
|
||||||
} else {
|
}
|
||||||
t.listeners[listenaddr] = l
|
t.listeners[listenaddr] = l
|
||||||
t.mutex.Unlock()
|
t.mutex.Unlock()
|
||||||
}
|
|
||||||
// And here we go!
|
// And here we go!
|
||||||
defer func() {
|
defer func() {
|
||||||
t.link.core.log.Infoln("Stopping TCP listener on:", l.Listener.Addr().String())
|
t.link.core.log.Infoln("Stopping TCP listener on:", l.Listener.Addr().String())
|
||||||
|
@ -363,9 +362,8 @@ func (t *tcp) handler(sock net.Conn, incoming bool, options interface{}, upgrade
|
||||||
if sock, err = upgrade.upgrade(sock); err != nil {
|
if sock, err = upgrade.upgrade(sock); err != nil {
|
||||||
t.link.core.log.Errorln("TCP handler upgrade failed:", err)
|
t.link.core.log.Errorln("TCP handler upgrade failed:", err)
|
||||||
return
|
return
|
||||||
} else {
|
|
||||||
upgraded = true
|
|
||||||
}
|
}
|
||||||
|
upgraded = true
|
||||||
}
|
}
|
||||||
stream := stream{}
|
stream := stream{}
|
||||||
stream.init(sock)
|
stream.init(sock)
|
||||||
|
|
|
@ -28,11 +28,11 @@ func version_getBaseMetadata() version_metadata {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gest the length of the metadata for this version, used to know how many bytes to read from the start of a connection.
|
// Gets the length of the metadata for this version, used to know how many bytes to read from the start of a connection.
|
||||||
func version_getMetaLength() (mlen int) {
|
func version_getMetaLength() (mlen int) {
|
||||||
mlen += 4 // meta
|
mlen += 4 // meta
|
||||||
mlen += 1 // ver, as long as it's < 127, which it is in this version
|
mlen++ // ver, as long as it's < 127, which it is in this version
|
||||||
mlen += 1 // minorVer, as long as it's < 127, which it is in this version
|
mlen++ // minorVer, as long as it's < 127, which it is in this version
|
||||||
mlen += crypto.BoxPubKeyLen // box
|
mlen += crypto.BoxPubKeyLen // box
|
||||||
mlen += crypto.SigPubKeyLen // sig
|
mlen += crypto.SigPubKeyLen // sig
|
||||||
mlen += crypto.BoxPubKeyLen // link
|
mlen += crypto.BoxPubKeyLen // link
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue