From 945656ccfd9db555a053e1f8898d97f93fe9180b Mon Sep 17 00:00:00 2001 From: lash Date: Fri, 5 Jan 2018 19:08:01 +0100 Subject: [PATCH] p2p/protocols, pot, swarm: Typos --- p2p/protocols/protocol.go | 2 +- p2p/protocols/protocol_test.go | 44 ++++++++++++++++----------------- pot/doc.go | 4 +-- pot/pot.go | 6 ++--- swarm/network/discovery_test.go | 2 +- swarm/network/hive_test.go | 2 +- swarm/network/kademlia.go | 2 +- swarm/network/protocol.go | 2 +- swarm/network/protocol_test.go | 8 +++--- swarm/pss/handshake.go | 4 +-- swarm/pss/pss.go | 2 +- swarm/pss/pss_test.go | 6 ++--- swarm/storage/chunker_test.go | 4 ++- 13 files changed, 45 insertions(+), 43 deletions(-) diff --git a/p2p/protocols/protocol.go b/p2p/protocols/protocol.go index 7b04069edf..bb934ca45a 100644 --- a/p2p/protocols/protocol.go +++ b/p2p/protocols/protocol.go @@ -183,7 +183,7 @@ type Peer struct { // NewPeer constructs a new peer // this constructor is called by the p2p.Protocol#Run function -// the first two arguments are comming the arguments passed to p2p.Protocol.Run function +// the first two arguments are coming the arguments passed to p2p.Protocol.Run function // the third argument is the CodeMap describing the protocol messages and options func NewPeer(p *p2p.Peer, rw p2p.MsgReadWriter, spec *Spec) *Peer { return &Peer{ diff --git a/p2p/protocols/protocol_test.go b/p2p/protocols/protocol_test.go index 149e19353c..a4641ed8bd 100644 --- a/p2p/protocols/protocol_test.go +++ b/p2p/protocols/protocol_test.go @@ -154,18 +154,18 @@ func protocolTester(t *testing.T, pp *p2ptest.TestPeerPool) *p2ptest.ProtocolTes func protoHandshakeExchange(id discover.NodeID, proto *protoHandshake) []p2ptest.Exchange { return []p2ptest.Exchange{ - p2ptest.Exchange{ + { Expects: []p2ptest.Expect{ - p2ptest.Expect{ + { Code: 0, Msg: &protoHandshake{42, "420"}, Peer: id, }, }, }, - p2ptest.Exchange{ + { Triggers: []p2ptest.Trigger{ - p2ptest.Trigger{ + { Code: 0, Msg: proto, Peer: id, @@ -207,18 +207,18 @@ func TestProtoHandshakeSuccess(t *testing.T) { func moduleHandshakeExchange(id discover.NodeID, resp uint) []p2ptest.Exchange { return []p2ptest.Exchange{ - p2ptest.Exchange{ + { Expects: []p2ptest.Expect{ - p2ptest.Expect{ + { Code: 1, Msg: &hs0{42}, Peer: id, }, }, }, - p2ptest.Exchange{ + { Triggers: []p2ptest.Trigger{ - p2ptest.Trigger{ + { Code: 1, Msg: &hs0{resp}, Peer: id, @@ -255,42 +255,42 @@ func TestModuleHandshakeSuccess(t *testing.T) { func testMultiPeerSetup(a, b discover.NodeID) []p2ptest.Exchange { return []p2ptest.Exchange{ - p2ptest.Exchange{ + { Label: "primary handshake", Expects: []p2ptest.Expect{ - p2ptest.Expect{ + { Code: 0, Msg: &protoHandshake{42, "420"}, Peer: a, }, - p2ptest.Expect{ + { Code: 0, Msg: &protoHandshake{42, "420"}, Peer: b, }, }, }, - p2ptest.Exchange{ + { Label: "module handshake", Triggers: []p2ptest.Trigger{ - p2ptest.Trigger{ + { Code: 0, Msg: &protoHandshake{42, "420"}, Peer: a, }, - p2ptest.Trigger{ + { Code: 0, Msg: &protoHandshake{42, "420"}, Peer: b, }, }, Expects: []p2ptest.Expect{ - p2ptest.Expect{ + { Code: 1, Msg: &hs0{42}, Peer: a, }, - p2ptest.Expect{ + { Code: 1, Msg: &hs0{42}, Peer: b, @@ -298,10 +298,10 @@ func testMultiPeerSetup(a, b discover.NodeID) []p2ptest.Exchange { }, }, - p2ptest.Exchange{Label: "alternative module handshake", Triggers: []p2ptest.Trigger{p2ptest.Trigger{Code: 1, Msg: &hs0{41}, Peer: a}, - p2ptest.Trigger{Code: 1, Msg: &hs0{41}, Peer: b}}}, - p2ptest.Exchange{Label: "repeated module handshake", Triggers: []p2ptest.Trigger{p2ptest.Trigger{Code: 1, Msg: &hs0{1}, Peer: a}}}, - p2ptest.Exchange{Label: "receiving repeated module handshake", Expects: []p2ptest.Expect{p2ptest.Expect{Code: 1, Msg: &hs0{43}, Peer: a}}}} + {Label: "alternative module handshake", Triggers: []p2ptest.Trigger{{Code: 1, Msg: &hs0{41}, Peer: a}, + {Code: 1, Msg: &hs0{41}, Peer: b}}}, + {Label: "repeated module handshake", Triggers: []p2ptest.Trigger{{Code: 1, Msg: &hs0{1}, Peer: a}}}, + {Label: "receiving repeated module handshake", Expects: []p2ptest.Expect{{Code: 1, Msg: &hs0{43}, Peer: a}}}} } func runMultiplePeers(t *testing.T, peer int, errs ...error) { @@ -332,7 +332,7 @@ func runMultiplePeers(t *testing.T, peer int, errs ...error) { // peer 0 sends kill request for peer with index s.TestExchanges(p2ptest.Exchange{ Triggers: []p2ptest.Trigger{ - p2ptest.Trigger{ + { Code: 2, Msg: &kill{s.IDs[peer]}, Peer: s.IDs[0], @@ -343,7 +343,7 @@ func runMultiplePeers(t *testing.T, peer int, errs ...error) { // the peer not killed sends a drop request s.TestExchanges(p2ptest.Exchange{ Triggers: []p2ptest.Trigger{ - p2ptest.Trigger{ + { Code: 3, Msg: &drop{}, Peer: s.IDs[(peer+1)%2], diff --git a/pot/doc.go b/pot/doc.go index 47d0357d93..4c0a03065d 100644 --- a/pot/doc.go +++ b/pot/doc.go @@ -48,8 +48,8 @@ concurrent routines, Pot * retrieval, insertion and deletion by key involves log(n) pointer lookups * for any item retrieval (defined as common prefix on the binary key) -* provide syncronous iterators respecting proximity ordering wrt any item -* provide asyncronous iterator (for parallel execution of operations) over n items +* provide synchronous iterators respecting proximity ordering wrt any item +* provide asynchronous iterator (for parallel execution of operations) over n items * allows cheap iteration over ranges * asymmetric concurrent merge (union) diff --git a/pot/pot.go b/pot/pot.go index 87f51af49c..dfda84804d 100644 --- a/pot/pot.go +++ b/pot/pot.go @@ -559,7 +559,7 @@ func (t *Pot) eachBin(val Val, pof Pof, po int, f func(int, int, func(func(val V } -// EachNeighbour is a syncronous iterator over neighbours of any target val +// EachNeighbour is a synchronous iterator over neighbours of any target val // the order of elements retrieved reflect proximity order to the target // TODO: add maximum proxbin to start range of iteration func (t *Pot) EachNeighbour(val Val, pof Pof, f func(Val, int) bool) bool { @@ -615,7 +615,7 @@ func (t *Pot) eachNeighbour(val Val, pof Pof, f func(Val, int) bool) bool { return true } -// EachNeighbourAsync called on (val, max, maxPos, f, wait) is an asyncronous iterator +// EachNeighbourAsync called on (val, max, maxPos, f, wait) is an asynchronous iterator // over elements not closer than maxPos wrt val. // val does not need to be match an element of the Pot, but if it does, and // maxPos is keylength than it is included in the iteration @@ -762,7 +762,7 @@ func (t *Pot) eachNeighbourAsync(val Val, pof Pof, max int, maxPos int, f func(V // getPos called on (n) returns the forking node at PO n and its index if it exists // otherwise nil -// caller is suppoed to hold the lock +// caller is supposed to hold the lock func (t *Pot) getPos(po int) (n *Pot, i int) { for i, n = range t.bins { if po > n.po { diff --git a/swarm/network/discovery_test.go b/swarm/network/discovery_test.go index ee90683a73..020a9b80dc 100644 --- a/swarm/network/discovery_test.go +++ b/swarm/network/discovery_test.go @@ -47,7 +47,7 @@ func TestDiscovery(t *testing.T) { s.TestExchanges(p2ptest.Exchange{ Label: "outgoing SubPeersMsg", Expects: []p2ptest.Expect{ - p2ptest.Expect{ + { Code: 3, Msg: &subPeersMsg{Depth: 0}, Peer: s.ProtocolTester.IDs[0], diff --git a/swarm/network/hive_test.go b/swarm/network/hive_test.go index 8e49e9029d..f55f14d5a4 100644 --- a/swarm/network/hive_test.go +++ b/swarm/network/hive_test.go @@ -46,7 +46,7 @@ func TestRegisterAndConnect(t *testing.T) { s.TestExchanges(p2ptest.Exchange{ Label: "getPeersMsg message", Expects: []p2ptest.Expect{ - p2ptest.Expect{ + { Code: 2, Msg: &subPeersMsg{0}, Peer: id, diff --git a/swarm/network/kademlia.go b/swarm/network/kademlia.go index 376ba9ad5a..d7bb7be6d7 100644 --- a/swarm/network/kademlia.go +++ b/swarm/network/kademlia.go @@ -424,7 +424,7 @@ func (k *Kademlia) callable(val pot.Val) OverlayAddr { return e.addr() } -// BaseAddr return the kademlia base addres +// BaseAddr return the kademlia base address func (k *Kademlia) BaseAddr() []byte { return k.base } diff --git a/swarm/network/protocol.go b/swarm/network/protocol.go index 22c8334030..d755f4a3fa 100644 --- a/swarm/network/protocol.go +++ b/swarm/network/protocol.go @@ -252,7 +252,7 @@ type bzzPeer struct { lastActive time.Time // time is updated whenever mutexes are releasing } -// Off returns the overlay peer record for offline persistance +// Off returns the overlay peer record for offline persistence func (p *bzzPeer) Off() OverlayAddr { return p.BzzAddr } diff --git a/swarm/network/protocol_test.go b/swarm/network/protocol_test.go index 1d7e165f02..e8ec4ebc37 100644 --- a/swarm/network/protocol_test.go +++ b/swarm/network/protocol_test.go @@ -57,18 +57,18 @@ func (t *testStore) Save(key string, v []byte) error { func HandshakeMsgExchange(lhs, rhs *HandshakeMsg, id discover.NodeID) []p2ptest.Exchange { return []p2ptest.Exchange{ - p2ptest.Exchange{ + { Expects: []p2ptest.Expect{ - p2ptest.Expect{ + { Code: 0, Msg: lhs, Peer: id, }, }, }, - p2ptest.Exchange{ + { Triggers: []p2ptest.Trigger{ - p2ptest.Trigger{ + { Code: 0, Msg: rhs, Peer: id, diff --git a/swarm/pss/handshake.go b/swarm/pss/handshake.go index 15f2a32a00..80aa729111 100644 --- a/swarm/pss/handshake.go +++ b/swarm/pss/handshake.go @@ -254,7 +254,7 @@ func (self *HandshakeController) cleanHandshake(pubkeyid string, topic *Topic, i func (self *HandshakeController) clean() { peerpubkeys := self.handshakes for pubkeyid, peertopics := range peerpubkeys { - for topic, _ := range peertopics { + for topic := range peertopics { self.cleanHandshake(pubkeyid, &topic, true, true) } } @@ -475,7 +475,7 @@ func (self *HandshakeAPI) AddHandshake(topic Topic) error { return nil } -// Deactivate handshake functionalty on a topic +// Deactivate handshake functionality on a topic func (self *HandshakeAPI) RemoveHandshake(topic *Topic) error { if _, ok := self.ctrl.deregisterFuncs[*topic]; ok { self.ctrl.deregisterFuncs[*topic]() diff --git a/swarm/pss/pss.go b/swarm/pss/pss.go index 0cd226ba08..5a35aba8c5 100644 --- a/swarm/pss/pss.go +++ b/swarm/pss/pss.go @@ -418,7 +418,7 @@ func (self *Pss) generateSymmetricKey(topic Topic, address *PssAddress, addToCac // If addtocache is set to true, the key will be added to the cache of keys // used to attempt symmetric decryption of incoming messages. // -// Returns a string id that can be used to retreive the key bytes +// Returns a string id that can be used to retrieve the key bytes // from the whisper backend (see pss.GetSymmetricKey()) func (self *Pss) SetSymmetricKey(key []byte, topic Topic, address *PssAddress, addtocache bool) (string, error) { keyid, err := self.w.AddSymKeyDirect(key) diff --git a/swarm/pss/pss_test.go b/swarm/pss/pss_test.go index 35f85e93f8..90e7e3ecb0 100644 --- a/swarm/pss/pss_test.go +++ b/swarm/pss/pss_test.go @@ -869,7 +869,7 @@ func benchmarkSymKeySend(b *testing.B) { } symkey, err := ps.w.GetSymKey(symkeyid) if err != nil { - b.Fatalf("could not retreive symkey: %v", err) + b.Fatalf("could not retrieve symkey: %v", err) } ps.SetSymmetricKey(symkey, topic, &to, false) @@ -962,7 +962,7 @@ func benchmarkSymkeyBruteforceChangeaddr(b *testing.B) { } symkey, err := ps.w.GetSymKey(keyid) if err != nil { - b.Fatalf("could not retreive symkey %s: %v", keyid, err) + b.Fatalf("could not retrieve symkey %s: %v", keyid, err) } wparams := &whisper.MessageParams{ TTL: defaultWhisperTTL, @@ -1046,7 +1046,7 @@ func benchmarkSymkeyBruteforceSameaddr(b *testing.B) { } symkey, err := ps.w.GetSymKey(keyid) if err != nil { - b.Fatalf("could not retreive symkey %s: %v", keyid, err) + b.Fatalf("could not retrieve symkey %s: %v", keyid, err) } wparams := &whisper.MessageParams{ TTL: defaultWhisperTTL, diff --git a/swarm/storage/chunker_test.go b/swarm/storage/chunker_test.go index 6b828970b6..19712a4709 100644 --- a/swarm/storage/chunker_test.go +++ b/swarm/storage/chunker_test.go @@ -113,7 +113,9 @@ func (self *chunkerTester) Append(chunker Splitter, rootKey Key, data io.Reader, // getting data chunk.SData = stored.SData chunk.Size = int64(binary.LittleEndian.Uint64(chunk.SData[0:8])) - close(chunk.C) + if chunk.C != nil { + close(chunk.C) + } } } }