cosmetic: linting

This commit is contained in:
Matthias Radestock committed 2015-03-27 00:43:26 +00:00
1 parent 2d83fcc398
commit e3ef5433cf
13 files changed
+48 -53

No files matched your search

+1 -1
View File
@@ -9,7 +9,7 @@ const (
EthernetOverhead = 14 EthernetOverhead = 14
UDPOverhead = 28 // 20 bytes for IPv4, 8 bytes for UDP UDPOverhead = 28 // 20 bytes for IPv4, 8 bytes for UDP
Port = 6783 Port = 6783
HttpPort = Port + 1 HTTPPort = Port + 1
DefaultPMTU = 65535 DefaultPMTU = 65535
MaxUDPPacketSize = 65536 MaxUDPPacketSize = 65536
ChannelSize = 16 ChannelSize = 16
+3 -4
View File
@@ -430,12 +430,11 @@ func (nd *NaClDecryptor) decrypt(buf []byte) ([]byte, error) {
} }
SetNonceLow15Bits(nonce, offsetNoFlags) SetNonceLow15Bits(nonce, offsetNoFlags)
result, success := secretbox.Open(nil, buf[2:], nonce, nd.conn.SessionKey) result, success := secretbox.Open(nil, buf[2:], nonce, nd.conn.SessionKey)
if success { if !success {
usedOffsets.Add(offsetNoFlagsInt)
return result, nil
} else {
return nil, fmt.Errorf("Unable to decrypt UDP packet") return nil, fmt.Errorf("Unable to decrypt UDP packet")
} }
usedOffsets.Add(offsetNoFlagsInt)
return result, nil
} }
// TCP Senders // TCP Senders
+18 -18
View File
@@ -114,25 +114,25 @@ func (conn *LocalConnection) Forward(df bool, frame *ForwardedFrame, dec *Ethern
return nil return nil
} }
return FrameTooBigError{EPMTU: effectivePMTU} 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 { func frameTooBig(frame *ForwardedFrame, effectivePMTU int) bool {
+6 -7
View File
@@ -140,15 +140,14 @@ func deliverGossipUnicast(channel *GossipChannel, srcName PeerName, origPayload
if err := dec.Decode(&destName); err != nil { if err := dec.Decode(&destName); err != nil {
return err return err
} }
if channel.ourself.Name == destName { if channel.ourself.Name != destName {
var payload []byte
if err := dec.Decode(&payload); err != nil {
return err
}
return channel.gossiper.OnGossipUnicast(srcName, payload)
} else {
return channel.relayGossipUnicast(destName, origPayload) 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 { func deliverGossipBroadcast(channel *GossipChannel, srcName PeerName, origPayload []byte, dec *gob.Decoder) error {
+2 -2
View File
@@ -87,7 +87,7 @@ func (conn *LocalConnection) handshake(enc *gob.Encoder, dec *gob.Decoder, accep
nameStr, _ := fv.Value("Name") nameStr, _ := fv.Value("Name")
nickNameStr, _ := fv.Value("NickName") nickNameStr, _ := fv.Value("NickName")
uidStr, _ := fv.Value("UID") uidStr, _ := fv.Value("UID")
remoteConnIdStr, _ := fv.Value("ConnID") remoteConnIDStr, _ := fv.Value("ConnID")
if err := fv.Err(); err != nil { if err := fv.Err(); err != nil {
return err return err
} }
@@ -108,7 +108,7 @@ func (conn *LocalConnection) handshake(enc *gob.Encoder, dec *gob.Decoder, accep
if err != nil { if err != nil {
return err return err
} }
remoteConnID, err := strconv.ParseUint(remoteConnIdStr, 10, 64) remoteConnID, err := strconv.ParseUint(remoteConnIDStr, 10, 64)
if err != nil { if err != nil {
return err return err
} }
+3 -3
View File
@@ -24,7 +24,7 @@ func (cache *MacCache) MarshalJSON() ([]byte, error) {
PeerName PeerName PeerName PeerName
LastSeen time.Time LastSeen time.Time
} }
entries := make([]*cacheEntry, 0) var entries []*cacheEntry
for key, entry := range cache.table { for key, entry := range cache.table {
entries = append(entries, &cacheEntry{intmac(key).String(), entry.peer.Name, entry.lastSeen}) 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) { func (peers *Peers) MarshalJSON() ([]byte, error) {
ps := make([]*Peer, 0) var ps []*Peer
peers.ForEach(func(_ PeerName, peer *Peer) { ps = append(ps, peer) }) peers.ForEach(func(_ PeerName, peer *Peer) { ps = append(ps, peer) })
return json.Marshal(ps) return json.Marshal(ps)
} }
@@ -71,7 +71,7 @@ func (peer *Peer) MarshalJSON() ([]byte, error) {
} }
func (conn *RemoteConnection) 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) { func (name PeerName) MarshalJSON() ([]byte, error) {
+1 -2
View File
@@ -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)) { if found && entry.peer == peer && now.Before(entry.lastSeen.Add(cache.maxAge/10)) {
cache.RUnlock() cache.RUnlock()
return false return false
} else {
cache.RUnlock()
} }
cache.RUnlock()
cache.Lock() cache.Lock()
defer cache.Unlock() defer cache.Unlock()
entry, found = cache.table[key] entry, found = cache.table[key]
+1 -1
View File
@@ -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 // Get all the peers from a Peers in a slice
func (peers *Peers) allPeers() []*Peer { func (peers *Peers) allPeers() []*Peer {
res := make([]*Peer, 0) var res []*Peer
for _, peer := range peers.table { for _, peer := range peers.table {
res = append(res, peer) res = append(res, peer)
} }
+5 -5
View File
@@ -45,13 +45,13 @@ func (peer *Peer) Version() uint64 {
func (peer *Peer) IncrementLocalRefCount() { func (peer *Peer) IncrementLocalRefCount() {
peer.Lock() peer.Lock()
defer peer.Unlock() defer peer.Unlock()
peer.localRefCount += 1 peer.localRefCount++
} }
func (peer *Peer) DecrementLocalRefCount() { func (peer *Peer) DecrementLocalRefCount() {
peer.Lock() peer.Lock()
defer peer.Unlock() defer peer.Unlock()
peer.localRefCount -= 1 peer.localRefCount--
} }
func (peer *Peer) IsLocallyReferenced() bool { func (peer *Peer) IsLocallyReferenced() bool {
@@ -94,20 +94,20 @@ func (peer *Peer) addConnection(conn Connection) {
peer.Lock() peer.Lock()
defer peer.Unlock() defer peer.Unlock()
peer.connections[conn.Remote().Name] = conn peer.connections[conn.Remote().Name] = conn
peer.version += 1 peer.version++
} }
func (peer *Peer) deleteConnection(conn Connection) { func (peer *Peer) deleteConnection(conn Connection) {
peer.Lock() peer.Lock()
defer peer.Unlock() defer peer.Unlock()
delete(peer.connections, conn.Remote().Name) delete(peer.connections, conn.Remote().Name)
peer.version += 1 peer.version++
} }
func (peer *Peer) connectionEstablished(conn Connection) { func (peer *Peer) connectionEstablished(conn Connection) {
peer.Lock() peer.Lock()
defer peer.Unlock() defer peer.Unlock()
peer.version += 1 peer.version++
} }
// Calculate the routing table from this peer to all peers reachable // Calculate the routing table from this peer to all peers reachable
+3 -4
View File
@@ -144,12 +144,11 @@ func (peers *Peers) String() string {
func (peers *Peers) fetchAlias(peer *Peer) (*Peer, bool) { func (peers *Peers) fetchAlias(peer *Peer) (*Peer, bool) {
if existingPeer, found := peers.table[peer.Name]; found { if existingPeer, found := peers.table[peer.Name]; found {
if existingPeer.UID == peer.UID { if existingPeer.UID != peer.UID {
existingPeer.IncrementLocalRefCount()
return existingPeer, true
} else {
return nil, true return nil, true
} }
existingPeer.IncrementLocalRefCount()
return existingPeer, true
} }
return nil, false return nil, false
} }
+1 -1
View File
@@ -45,7 +45,7 @@ func TestPeersEncoding(t *testing.T) {
peer[i], ps[i] = newNode(name) 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++ { for i := 0; i < numIters; i++ {
oper := rand.Intn(2) oper := rand.Intn(2)
switch oper { switch oper {
+1 -2
View File
@@ -122,7 +122,6 @@ func NormalisePeerAddr(peerAddr string) string {
_, _, err := net.SplitHostPort(peerAddr) _, _, err := net.SplitHostPort(peerAddr)
if err == nil { if err == nil {
return peerAddr return peerAddr
} else {
return fmt.Sprintf("%s:%d", peerAddr, Port)
} }
return fmt.Sprintf("%s:%d", peerAddr, Port)
} }
+3 -3
View File
@@ -144,11 +144,11 @@ func main() {
log.Fatal(err) log.Fatal(err)
} }
} }
go handleHttp(router) go handleHTTP(router)
handleSignals(router) handleSignals(router)
} }
func handleHttp(router *weave.Router) { func handleHTTP(router *weave.Router) {
encryption := "off" encryption := "off"
if router.UsingPassword() { if router.UsingPassword() {
encryption = "on" encryption = "on"
@@ -178,7 +178,7 @@ func handleHttp(router *weave.Router) {
http.Handle("/", muxRouter) http.Handle("/", muxRouter)
address := fmt.Sprintf(":%d", weave.HttpPort) address := fmt.Sprintf(":%d", weave.HTTPPort)
err := http.ListenAndServe(address, nil) err := http.ListenAndServe(address, nil)
if err != nil { if err != nil {
log.Fatal("Unable to create http listener: ", err) log.Fatal("Unable to create http listener: ", err)