Fix lint errors

This commit is contained in:
Neil Alexander 2021-06-02 14:40:09 +01:00
parent 166336a418
commit 8932ab0519
14 changed files with 44 additions and 54 deletions

View File

@ -107,7 +107,9 @@ func readConfig(useconf *bool, useconffile *string, normaliseconf *bool) *config
if err != nil { if err != nil {
panic(err) panic(err)
} }
json.Unmarshal(confJson, &cfg) if err := json.Unmarshal(confJson, &cfg); err != nil {
panic(err)
}
// Overlay our newly mapped configuration onto the autoconf node config that // Overlay our newly mapped configuration onto the autoconf node config that
// we generated above. // we generated above.
if err = mapstructure.Decode(dat, &cfg); err != nil { if err = mapstructure.Decode(dat, &cfg); err != nil {
@ -283,20 +285,23 @@ func main() {
n.tuntap = &tuntap.TunAdapter{} n.tuntap = &tuntap.TunAdapter{}
n.tuntap.(*tuntap.TunAdapter).SetSessionGatekeeper(n.sessionFirewall) n.tuntap.(*tuntap.TunAdapter).SetSessionGatekeeper(n.sessionFirewall)
// Start the admin socket // Start the admin socket
n.admin.Init(&n.core, cfg, logger, nil) if err := n.admin.Init(&n.core, cfg, logger, nil); err != nil {
if err := n.admin.Start(); err != nil { logger.Errorln("An error occured initialising admin socket:", err)
} else if err := n.admin.Start(); err != nil {
logger.Errorln("An error occurred starting admin socket:", err) logger.Errorln("An error occurred starting admin socket:", err)
} }
n.admin.SetupAdminHandlers(n.admin.(*admin.AdminSocket)) n.admin.SetupAdminHandlers(n.admin.(*admin.AdminSocket))
// Start the multicast interface // Start the multicast interface
n.multicast.Init(&n.core, cfg, logger, nil) if err := n.multicast.Init(&n.core, cfg, logger, nil); err != nil {
if err := n.multicast.Start(); err != nil { logger.Errorln("An error occured initialising multicast:", err)
} else if err := n.multicast.Start(); err != nil {
logger.Errorln("An error occurred starting multicast:", err) logger.Errorln("An error occurred starting multicast:", err)
} }
n.multicast.SetupAdminHandlers(n.admin.(*admin.AdminSocket)) n.multicast.SetupAdminHandlers(n.admin.(*admin.AdminSocket))
// Start the TUN/TAP interface // Start the TUN/TAP interface
n.tuntap.Init(&n.core, cfg, logger, nil) if err := n.tuntap.Init(&n.core, cfg, logger, nil); err != nil {
if err := n.tuntap.Start(); err != nil { logger.Errorln("An error occurred initialising TUN/TAP:", err)
} else if err := n.tuntap.Start(); err != nil {
logger.Errorln("An error occurred starting TUN/TAP:", err) logger.Errorln("An error occurred starting TUN/TAP:", err)
} }
n.tuntap.SetupAdminHandlers(n.admin.(*admin.AdminSocket)) n.tuntap.SetupAdminHandlers(n.admin.(*admin.AdminSocket))
@ -316,9 +321,9 @@ func main() {
} }
func (n *node) shutdown() { func (n *node) shutdown() {
n.admin.Stop() _ = n.admin.Stop()
n.multicast.Stop() _ = n.multicast.Stop()
n.tuntap.Stop() _ = n.tuntap.Stop()
n.core.Stop() n.core.Stop()
} }

View File

@ -47,8 +47,8 @@ func run() int {
fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [options] command [key=value] [key=value] ...\n\n", os.Args[0]) fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [options] command [key=value] [key=value] ...\n\n", os.Args[0])
fmt.Println("Options:") fmt.Println("Options:")
flag.PrintDefaults() flag.PrintDefaults()
fmt.Println("\nPlease note that options must always specified BEFORE the command\non the command line or they will be ignored.\n") fmt.Println("\nPlease note that options must always specified BEFORE the command\non the command line or they will be ignored.\n") // nolint:govet
fmt.Println("Commands:\n - Use \"list\" for a list of available commands\n") fmt.Println("Commands:\n - Use \"list\" for a list of available commands\n") // nolint:govet
fmt.Println("Examples:") fmt.Println("Examples:")
fmt.Println(" - ", os.Args[0], "list") fmt.Println(" - ", os.Args[0], "list")
fmt.Println(" - ", os.Args[0], "getPeers") fmt.Println(" - ", os.Args[0], "getPeers")

View File

@ -158,7 +158,7 @@ func (c *Core) _stop() {
c.addPeerTimer.Stop() c.addPeerTimer.Stop()
c.addPeerTimer = nil c.addPeerTimer = nil
} }
c.links.stop() _ = c.links.stop()
/* FIXME this deadlocks, need a waitgroup or something to coordinate shutdown /* FIXME this deadlocks, need a waitgroup or something to coordinate shutdown
for _, peer := range c.GetPeers() { for _, peer := range c.GetPeers() {
c.DisconnectPeer(peer.Port) c.DisconnectPeer(peer.Port)

View File

@ -250,15 +250,3 @@ func (intf *link) close() {
func (intf *link) name() string { func (intf *link) name() string {
return intf.lname return intf.lname
} }
func (intf *link) local() string {
return intf.info.local
}
func (intf *link) remote() string {
return intf.info.remote
}
func (intf *link) interfaceType() string {
return intf.info.linkType
}

View File

@ -67,7 +67,7 @@ type tcpOptions struct {
} }
func (l *TcpListener) Stop() { func (l *TcpListener) Stop() {
defer func() { recover() }() defer func() { _ = recover() }()
close(l.stop) close(l.stop)
} }
@ -75,7 +75,7 @@ func (l *TcpListener) Stop() {
func (t *tcp) setExtraOptions(c net.Conn) { func (t *tcp) setExtraOptions(c net.Conn) {
switch sock := c.(type) { switch sock := c.(type) {
case *net.TCPConn: case *net.TCPConn:
sock.SetNoDelay(true) _ = sock.SetNoDelay(true)
// TODO something for socks5 // TODO something for socks5
default: default:
} }

View File

@ -91,7 +91,7 @@ func (m *Multicast) _start() error {
return err return err
} }
m.sock = ipv6.NewPacketConn(conn) m.sock = ipv6.NewPacketConn(conn)
if err = m.sock.SetControlMessage(ipv6.FlagDst, true); err != nil { if err = m.sock.SetControlMessage(ipv6.FlagDst, true); err != nil { // nolint:staticcheck
// Windows can't set this flag, so we need to handle it in other ways // Windows can't set this flag, so we need to handle it in other ways
} }
@ -269,7 +269,7 @@ func (m *Multicast) _announce() {
continue continue
} }
// Join the multicast group // Join the multicast group
m.sock.JoinGroup(&iface, groupAddr) _ = m.sock.JoinGroup(&iface, groupAddr)
// Try and see if we already have a TCP listener for this interface // Try and see if we already have a TCP listener for this interface
var info *listenerInfo var info *listenerInfo
if nfo, ok := m.listeners[iface.Name]; !ok || nfo.listener.Listener == nil { if nfo, ok := m.listeners[iface.Name]; !ok || nfo.listener.Listener == nil {
@ -304,7 +304,7 @@ func (m *Multicast) _announce() {
a.Zone = "" a.Zone = ""
destAddr.Zone = iface.Name destAddr.Zone = iface.Name
msg := []byte(a.String()) msg := []byte(a.String())
m.sock.WriteTo(msg, nil, destAddr) _, _ = m.sock.WriteTo(msg, nil, destAddr)
} }
if info.interval.Seconds() < 15 { if info.interval.Seconds() < 15 {
info.interval += time.Second info.interval += time.Second

View File

@ -29,8 +29,6 @@ import (
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
var awdlGoroutineStarted bool
func (m *Multicast) _multicastStarted() { func (m *Multicast) _multicastStarted() {
if !m.isOpen { if !m.isOpen {
return return

View File

@ -123,16 +123,12 @@ func (tun *TunAdapter) write() {
continue // bad remote address/subnet continue // bad remote address/subnet
} }
bs = buf[:TUN_OFFSET_BYTES+len(bs)] bs = buf[:TUN_OFFSET_BYTES+len(bs)]
n, err = tun.iface.Write(bs, TUN_OFFSET_BYTES) if _, err = tun.iface.Write(bs, TUN_OFFSET_BYTES); err != nil {
if err != nil {
tun.Act(nil, func() { tun.Act(nil, func() {
if !tun.isOpen { if !tun.isOpen {
tun.log.Errorln("TUN iface write error:", err) tun.log.Errorln("TUN iface write error:", err)
} }
}) })
} }
if n != len(bs) {
// TODO some kind of error reporting for a partial write
}
} }
} }

View File

@ -50,7 +50,7 @@ func (k *keyStore) sendToAddress(addr address.Address, bs []byte) {
if info := k.addrToInfo[addr]; info != nil { if info := k.addrToInfo[addr]; info != nil {
k.resetTimeout(info) k.resetTimeout(info)
k.mutex.Unlock() k.mutex.Unlock()
k.tun.core.WriteTo(bs, iwt.Addr(info.key[:])) _, _ = k.tun.core.WriteTo(bs, iwt.Addr(info.key[:]))
} else { } else {
var buf *buffer var buf *buffer
if buf = k.addrBuffer[addr]; buf == nil { if buf = k.addrBuffer[addr]; buf == nil {
@ -79,7 +79,7 @@ func (k *keyStore) sendToSubnet(subnet address.Subnet, bs []byte) {
if info := k.subnetToInfo[subnet]; info != nil { if info := k.subnetToInfo[subnet]; info != nil {
k.resetTimeout(info) k.resetTimeout(info)
k.mutex.Unlock() k.mutex.Unlock()
k.tun.core.WriteTo(bs, iwt.Addr(info.key[:])) _, _ = k.tun.core.WriteTo(bs, iwt.Addr(info.key[:]))
} else { } else {
var buf *buffer var buf *buffer
if buf = k.subnetBuffer[subnet]; buf == nil { if buf = k.subnetBuffer[subnet]; buf == nil {
@ -132,13 +132,13 @@ func (k *keyStore) update(key ed25519.PublicKey) *keyInfo {
k.mutex.Unlock() k.mutex.Unlock()
if buf := k.addrBuffer[info.address]; buf != nil { if buf := k.addrBuffer[info.address]; buf != nil {
for _, bs := range buf.packets { for _, bs := range buf.packets {
k.tun.core.WriteTo(bs, iwt.Addr(info.key[:])) _, _ = k.tun.core.WriteTo(bs, iwt.Addr(info.key[:]))
} }
delete(k.addrBuffer, info.address) delete(k.addrBuffer, info.address)
} }
if buf := k.subnetBuffer[info.subnet]; buf != nil { if buf := k.subnetBuffer[info.subnet]; buf != nil {
for _, bs := range buf.packets { for _, bs := range buf.packets {
k.tun.core.WriteTo(bs, iwt.Addr(info.key[:])) _, _ = k.tun.core.WriteTo(bs, iwt.Addr(info.key[:]))
} }
delete(k.subnetBuffer, info.subnet) delete(k.subnetBuffer, info.subnet)
} }

View File

@ -129,7 +129,7 @@ func (m *nodeinfo) _sendReq(key keyArray, callback func(nodeinfo NodeInfoPayload
if callback != nil { if callback != nil {
m._addCallback(key, callback) m._addCallback(key, callback)
} }
m.proto.tun.core.WriteTo([]byte{typeSessionProto, typeProtoNodeInfoRequest}, iwt.Addr(key[:])) _, _ = m.proto.tun.core.WriteTo([]byte{typeSessionProto, typeProtoNodeInfoRequest}, iwt.Addr(key[:]))
} }
func (m *nodeinfo) handleReq(from phony.Actor, key keyArray) { func (m *nodeinfo) handleReq(from phony.Actor, key keyArray) {
@ -146,7 +146,7 @@ func (m *nodeinfo) handleRes(from phony.Actor, key keyArray, info NodeInfoPayloa
func (m *nodeinfo) _sendRes(key keyArray) { func (m *nodeinfo) _sendRes(key keyArray) {
bs := append([]byte{typeSessionProto, typeProtoNodeInfoResponse}, m._getNodeInfo()...) bs := append([]byte{typeSessionProto, typeProtoNodeInfoResponse}, m._getNodeInfo()...)
m.proto.tun.core.WriteTo(bs, iwt.Addr(key[:])) _, _ = m.proto.tun.core.WriteTo(bs, iwt.Addr(key[:]))
} }
// Admin socket stuff // Admin socket stuff

View File

@ -209,7 +209,7 @@ func (p *protoHandler) _handleGetDHTResponse(key keyArray, bs []byte) {
func (p *protoHandler) _sendDebug(key keyArray, dType uint8, data []byte) { func (p *protoHandler) _sendDebug(key keyArray, dType uint8, data []byte) {
bs := append([]byte{typeSessionProto, typeProtoDebug, dType}, data...) bs := append([]byte{typeSessionProto, typeProtoDebug, dType}, data...)
p.tun.core.WriteTo(bs, iwt.Addr(key[:])) _, _ = p.tun.core.WriteTo(bs, iwt.Addr(key[:]))
} }
// Admin socket stuff // Admin socket stuff

View File

@ -221,13 +221,13 @@ func (tun *TunAdapter) oobHandler(fromKey, toKey ed25519.PublicKey, data []byte)
func (tun *TunAdapter) sendKeyLookup(partial ed25519.PublicKey) { func (tun *TunAdapter) sendKeyLookup(partial ed25519.PublicKey) {
sig := ed25519.Sign(tun.core.PrivateKey(), partial[:]) sig := ed25519.Sign(tun.core.PrivateKey(), partial[:])
bs := append([]byte{typeKeyLookup}, sig...) bs := append([]byte{typeKeyLookup}, sig...)
tun.core.SendOutOfBand(partial, bs) _ = tun.core.SendOutOfBand(partial, bs)
} }
func (tun *TunAdapter) sendKeyResponse(dest ed25519.PublicKey) { func (tun *TunAdapter) sendKeyResponse(dest ed25519.PublicKey) {
sig := ed25519.Sign(tun.core.PrivateKey(), dest[:]) sig := ed25519.Sign(tun.core.PrivateKey(), dest[:])
bs := append([]byte{typeKeyResponse}, sig...) bs := append([]byte{typeKeyResponse}, sig...)
tun.core.SendOutOfBand(dest, bs) _ = tun.core.SendOutOfBand(dest, bs)
} }
func (tun *TunAdapter) maxSessionMTU() uint64 { func (tun *TunAdapter) maxSessionMTU() uint64 {

View File

@ -40,26 +40,29 @@ const (
darwin_ND6_INFINITE_LIFETIME = 0xFFFFFFFF // netinet6/nd6.h darwin_ND6_INFINITE_LIFETIME = 0xFFFFFFFF // netinet6/nd6.h
) )
// nolint:structcheck
type in6_addrlifetime struct { type in6_addrlifetime struct {
ia6t_expire float64 ia6t_expire float64 // nolint:unused
ia6t_preferred float64 ia6t_preferred float64 // nolint:unused
ia6t_vltime uint32 ia6t_vltime uint32
ia6t_pltime uint32 ia6t_pltime uint32
} }
// nolint:structcheck
type sockaddr_in6 struct { type sockaddr_in6 struct {
sin6_len uint8 sin6_len uint8
sin6_family uint8 sin6_family uint8
sin6_port uint8 sin6_port uint8 // nolint:unused
sin6_flowinfo uint32 sin6_flowinfo uint32 // nolint:unused
sin6_addr [8]uint16 sin6_addr [8]uint16
sin6_scope_id uint32 sin6_scope_id uint32 // nolint:unused
} }
// nolint:structcheck
type in6_aliasreq struct { type in6_aliasreq struct {
ifra_name [16]byte ifra_name [16]byte
ifra_addr sockaddr_in6 ifra_addr sockaddr_in6
ifra_dstaddr sockaddr_in6 ifra_dstaddr sockaddr_in6 // nolint:unused
ifra_prefixmask sockaddr_in6 ifra_prefixmask sockaddr_in6
ifra_flags uint32 ifra_flags uint32
ifra_lifetime in6_addrlifetime ifra_lifetime in6_addrlifetime

View File

@ -2,14 +2,14 @@ package tuntap
// Out-of-band packet types // Out-of-band packet types
const ( const (
typeKeyDummy = iota typeKeyDummy = iota // nolint:deadcode,varcheck
typeKeyLookup typeKeyLookup
typeKeyResponse typeKeyResponse
) )
// In-band packet types // In-band packet types
const ( const (
typeSessionDummy = iota typeSessionDummy = iota // nolint:deadcode,varcheck
typeSessionTraffic typeSessionTraffic
typeSessionProto typeSessionProto
) )