cosmetic: linting
This commit is contained in:
1 parent
2d83fcc398
commit
e3ef5433cf
13 files changed
+48
-53
No files matched your search
+1
-1
@@ -9,7 +9,7 @@ const (
|
||||
EthernetOverhead = 14
|
||||
UDPOverhead = 28 // 20 bytes for IPv4, 8 bytes for UDP
|
||||
Port = 6783
|
||||
HttpPort = Port + 1
|
||||
HTTPPort = Port + 1
|
||||
DefaultPMTU = 65535
|
||||
MaxUDPPacketSize = 65536
|
||||
ChannelSize = 16
|
||||
|
||||
+3
-4
@@ -430,12 +430,11 @@ func (nd *NaClDecryptor) decrypt(buf []byte) ([]byte, error) {
|
||||
}
|
||||
SetNonceLow15Bits(nonce, offsetNoFlags)
|
||||
result, success := secretbox.Open(nil, buf[2:], nonce, nd.conn.SessionKey)
|
||||
if success {
|
||||
usedOffsets.Add(offsetNoFlagsInt)
|
||||
return result, nil
|
||||
} else {
|
||||
if !success {
|
||||
return nil, fmt.Errorf("Unable to decrypt UDP packet")
|
||||
}
|
||||
usedOffsets.Add(offsetNoFlagsInt)
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// TCP Senders
|
||||
|
||||
+18
-18
@@ -114,25 +114,25 @@ func (conn *LocalConnection) Forward(df bool, frame *ForwardedFrame, dec *Ethern
|
||||
return nil
|
||||
}
|
||||
return FrameTooBigError{EPMTU: effectivePMTU}
|
||||
} else {
|
||||
if stackFrag || dec == nil || len(dec.decoded) < 2 {
|
||||
forwardChan <- frame
|
||||
return nil
|
||||
}
|
||||
// Don't have trustworthy stack, so we're going to have to
|
||||
// send it DF in any case.
|
||||
if !frameTooBig(frame, effectivePMTU) {
|
||||
forwardChanDF <- frame
|
||||
return nil
|
||||
}
|
||||
conn.Router.LogFrame("Fragmenting", frame.frame, &dec.eth)
|
||||
// We can't trust the stack to fragment, we have IP, and we
|
||||
// have a frame that's too big for the MTU, so we have to
|
||||
// fragment it ourself.
|
||||
return fragment(dec.eth, dec.ip, effectivePMTU, frame, func(segFrame *ForwardedFrame) {
|
||||
forwardChanDF <- segFrame
|
||||
})
|
||||
}
|
||||
|
||||
if stackFrag || dec == nil || len(dec.decoded) < 2 {
|
||||
forwardChan <- frame
|
||||
return nil
|
||||
}
|
||||
// Don't have trustworthy stack, so we're going to have to
|
||||
// send it DF in any case.
|
||||
if !frameTooBig(frame, effectivePMTU) {
|
||||
forwardChanDF <- frame
|
||||
return nil
|
||||
}
|
||||
conn.Router.LogFrame("Fragmenting", frame.frame, &dec.eth)
|
||||
// We can't trust the stack to fragment, we have IP, and we
|
||||
// have a frame that's too big for the MTU, so we have to
|
||||
// fragment it ourself.
|
||||
return fragment(dec.eth, dec.ip, effectivePMTU, frame, func(segFrame *ForwardedFrame) {
|
||||
forwardChanDF <- segFrame
|
||||
})
|
||||
}
|
||||
|
||||
func frameTooBig(frame *ForwardedFrame, effectivePMTU int) bool {
|
||||
|
||||
+6
-7
@@ -140,15 +140,14 @@ func deliverGossipUnicast(channel *GossipChannel, srcName PeerName, origPayload
|
||||
if err := dec.Decode(&destName); err != nil {
|
||||
return err
|
||||
}
|
||||
if channel.ourself.Name == destName {
|
||||
var payload []byte
|
||||
if err := dec.Decode(&payload); err != nil {
|
||||
return err
|
||||
}
|
||||
return channel.gossiper.OnGossipUnicast(srcName, payload)
|
||||
} else {
|
||||
if channel.ourself.Name != destName {
|
||||
return channel.relayGossipUnicast(destName, origPayload)
|
||||
}
|
||||
var payload []byte
|
||||
if err := dec.Decode(&payload); err != nil {
|
||||
return err
|
||||
}
|
||||
return channel.gossiper.OnGossipUnicast(srcName, payload)
|
||||
}
|
||||
|
||||
func deliverGossipBroadcast(channel *GossipChannel, srcName PeerName, origPayload []byte, dec *gob.Decoder) error {
|
||||
|
||||
+2
-2
@@ -87,7 +87,7 @@ func (conn *LocalConnection) handshake(enc *gob.Encoder, dec *gob.Decoder, accep
|
||||
nameStr, _ := fv.Value("Name")
|
||||
nickNameStr, _ := fv.Value("NickName")
|
||||
uidStr, _ := fv.Value("UID")
|
||||
remoteConnIdStr, _ := fv.Value("ConnID")
|
||||
remoteConnIDStr, _ := fv.Value("ConnID")
|
||||
if err := fv.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -108,7 +108,7 @@ func (conn *LocalConnection) handshake(enc *gob.Encoder, dec *gob.Decoder, accep
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
remoteConnID, err := strconv.ParseUint(remoteConnIdStr, 10, 64)
|
||||
remoteConnID, err := strconv.ParseUint(remoteConnIDStr, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+3
-3
@@ -24,7 +24,7 @@ func (cache *MacCache) MarshalJSON() ([]byte, error) {
|
||||
PeerName PeerName
|
||||
LastSeen time.Time
|
||||
}
|
||||
entries := make([]*cacheEntry, 0)
|
||||
var entries []*cacheEntry
|
||||
for key, entry := range cache.table {
|
||||
entries = append(entries, &cacheEntry{intmac(key).String(), entry.peer.Name, entry.lastSeen})
|
||||
}
|
||||
@@ -32,7 +32,7 @@ func (cache *MacCache) MarshalJSON() ([]byte, error) {
|
||||
}
|
||||
|
||||
func (peers *Peers) MarshalJSON() ([]byte, error) {
|
||||
ps := make([]*Peer, 0)
|
||||
var ps []*Peer
|
||||
peers.ForEach(func(_ PeerName, peer *Peer) { ps = append(ps, peer) })
|
||||
return json.Marshal(ps)
|
||||
}
|
||||
@@ -71,7 +71,7 @@ func (peer *Peer) MarshalJSON() ([]byte, error) {
|
||||
}
|
||||
|
||||
func (conn *RemoteConnection) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(struct{ RemoteName, TcpAddr string }{conn.Remote().Name.String(), conn.RemoteTCPAddr()})
|
||||
return json.Marshal(struct{ RemoteName, TCPAddr string }{conn.Remote().Name.String(), conn.RemoteTCPAddr()})
|
||||
}
|
||||
|
||||
func (name PeerName) MarshalJSON() ([]byte, error) {
|
||||
|
||||
+1
-2
@@ -40,9 +40,8 @@ func (cache *MacCache) Enter(mac net.HardwareAddr, peer *Peer) bool {
|
||||
if found && entry.peer == peer && now.Before(entry.lastSeen.Add(cache.maxAge/10)) {
|
||||
cache.RUnlock()
|
||||
return false
|
||||
} else {
|
||||
cache.RUnlock()
|
||||
}
|
||||
cache.RUnlock()
|
||||
cache.Lock()
|
||||
defer cache.Unlock()
|
||||
entry, found = cache.table[key]
|
||||
|
||||
@@ -67,7 +67,7 @@ func checkEqualConns(t *testing.T, ourName PeerName, got, wanted map[PeerName]Co
|
||||
|
||||
// Get all the peers from a Peers in a slice
|
||||
func (peers *Peers) allPeers() []*Peer {
|
||||
res := make([]*Peer, 0)
|
||||
var res []*Peer
|
||||
for _, peer := range peers.table {
|
||||
res = append(res, peer)
|
||||
}
|
||||
|
||||
+5
-5
@@ -45,13 +45,13 @@ func (peer *Peer) Version() uint64 {
|
||||
func (peer *Peer) IncrementLocalRefCount() {
|
||||
peer.Lock()
|
||||
defer peer.Unlock()
|
||||
peer.localRefCount += 1
|
||||
peer.localRefCount++
|
||||
}
|
||||
|
||||
func (peer *Peer) DecrementLocalRefCount() {
|
||||
peer.Lock()
|
||||
defer peer.Unlock()
|
||||
peer.localRefCount -= 1
|
||||
peer.localRefCount--
|
||||
}
|
||||
|
||||
func (peer *Peer) IsLocallyReferenced() bool {
|
||||
@@ -94,20 +94,20 @@ func (peer *Peer) addConnection(conn Connection) {
|
||||
peer.Lock()
|
||||
defer peer.Unlock()
|
||||
peer.connections[conn.Remote().Name] = conn
|
||||
peer.version += 1
|
||||
peer.version++
|
||||
}
|
||||
|
||||
func (peer *Peer) deleteConnection(conn Connection) {
|
||||
peer.Lock()
|
||||
defer peer.Unlock()
|
||||
delete(peer.connections, conn.Remote().Name)
|
||||
peer.version += 1
|
||||
peer.version++
|
||||
}
|
||||
|
||||
func (peer *Peer) connectionEstablished(conn Connection) {
|
||||
peer.Lock()
|
||||
defer peer.Unlock()
|
||||
peer.version += 1
|
||||
peer.version++
|
||||
}
|
||||
|
||||
// Calculate the routing table from this peer to all peers reachable
|
||||
|
||||
+3
-4
@@ -144,12 +144,11 @@ func (peers *Peers) String() string {
|
||||
|
||||
func (peers *Peers) fetchAlias(peer *Peer) (*Peer, bool) {
|
||||
if existingPeer, found := peers.table[peer.Name]; found {
|
||||
if existingPeer.UID == peer.UID {
|
||||
existingPeer.IncrementLocalRefCount()
|
||||
return existingPeer, true
|
||||
} else {
|
||||
if existingPeer.UID != peer.UID {
|
||||
return nil, true
|
||||
}
|
||||
existingPeer.IncrementLocalRefCount()
|
||||
return existingPeer, true
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ func TestPeersEncoding(t *testing.T) {
|
||||
peer[i], ps[i] = newNode(name)
|
||||
}
|
||||
|
||||
conns := make([]struct{ from, to int }, 0)
|
||||
var conns []struct{ from, to int }
|
||||
for i := 0; i < numIters; i++ {
|
||||
oper := rand.Intn(2)
|
||||
switch oper {
|
||||
|
||||
+1
-2
@@ -122,7 +122,6 @@ func NormalisePeerAddr(peerAddr string) string {
|
||||
_, _, err := net.SplitHostPort(peerAddr)
|
||||
if err == nil {
|
||||
return peerAddr
|
||||
} else {
|
||||
return fmt.Sprintf("%s:%d", peerAddr, Port)
|
||||
}
|
||||
return fmt.Sprintf("%s:%d", peerAddr, Port)
|
||||
}
|
||||
+3
-3
@@ -144,11 +144,11 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
go handleHttp(router)
|
||||
go handleHTTP(router)
|
||||
handleSignals(router)
|
||||
}
|
||||
|
||||
func handleHttp(router *weave.Router) {
|
||||
func handleHTTP(router *weave.Router) {
|
||||
encryption := "off"
|
||||
if router.UsingPassword() {
|
||||
encryption = "on"
|
||||
@@ -178,7 +178,7 @@ func handleHttp(router *weave.Router) {
|
||||
|
||||
http.Handle("/", muxRouter)
|
||||
|
||||
address := fmt.Sprintf(":%d", weave.HttpPort)
|
||||
address := fmt.Sprintf(":%d", weave.HTTPPort)
|
||||
err := http.ListenAndServe(address, nil)
|
||||
if err != nil {
|
||||
log.Fatal("Unable to create http listener: ", err)
|
||||
|
||||
Reference in new issue
Block a user