MCPcopy Create free account
hub / github.com/DeAI-Artist/Linkis / Add

Method Add

p2p/peer_set.go:43–60  ·  view source on GitHub ↗

Add adds the peer to the PeerSet. It returns an error carrying the reason, if the peer is already present.

(peer Peer)

Source from the content-addressed store, hash-verified

41// Add adds the peer to the PeerSet.
42// It returns an error carrying the reason, if the peer is already present.
43func (ps *PeerSet) Add(peer Peer) error {
44 ps.mtx.Lock()
45 defer ps.mtx.Unlock()
46
47 if ps.lookup[peer.ID()] != nil {
48 return ErrSwitchDuplicatePeerID{peer.ID()}
49 }
50 if peer.GetRemovalFailed() {
51 return ErrPeerRemoval{}
52 }
53
54 index := len(ps.list)
55 // Appending is safe even with other goroutines
56 // iterating over the ps.list slice.
57 ps.list = append(ps.list, peer)
58 ps.lookup[peer.ID()] = &peerSetItem{peer, index}
59 return nil
60}
61
62// Has returns true if the set contains the peer referred to by this
63// peerKey, otherwise false.

Callers 15

TestPeerSetAddRemoveOneFunction · 0.95
TestPeerSetAddRemoveManyFunction · 0.95
TestPeerSetAddDuplicateFunction · 0.95
globalCbMethod · 0.45
resCbFirstTimeMethod · 0.45
TestReactorConcurrencyFunction · 0.45
waitForTxsOnReactorsFunction · 0.45
addNewTransactionMethod · 0.45
handleRecheckResultMethod · 0.45
purgeExpiredTxsMethod · 0.45
waitForTxsOnReactorsFunction · 0.45

Calls 4

LockMethod · 0.65
UnlockMethod · 0.65
IDMethod · 0.65
GetRemovalFailedMethod · 0.65

Tested by 15

TestPeerSetAddRemoveOneFunction · 0.76
TestPeerSetAddRemoveManyFunction · 0.76
TestPeerSetAddDuplicateFunction · 0.76
TestReactorConcurrencyFunction · 0.36
waitForTxsOnReactorsFunction · 0.36
waitForTxsOnReactorsFunction · 0.36
TestWeightedMedianFunction · 0.36
TestSignVoteFunction · 0.36