-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat/autosharding-config
- Loading branch information
Showing
11 changed files
with
254 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
plugins: | ||
golint: | ||
enabled: true | ||
gofmt: | ||
enabled: true | ||
govet: | ||
enabled: true | ||
# golangci-lint: | ||
#enabled: true | ||
exclude_patterns: | ||
- "." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package peermanager | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
|
||
"github.com/libp2p/go-libp2p/core/peer" | ||
) | ||
|
||
// TestPeerDiscoverer is mock peer discoverer for testing | ||
type TestPeerDiscoverer struct { | ||
sync.RWMutex | ||
peerMap map[peer.ID]struct{} | ||
} | ||
|
||
// NewTestPeerDiscoverer is a constructor for TestPeerDiscoverer | ||
func NewTestPeerDiscoverer() *TestPeerDiscoverer { | ||
result := &TestPeerDiscoverer{ | ||
peerMap: make(map[peer.ID]struct{}), | ||
} | ||
|
||
return result | ||
} | ||
|
||
// Subscribe is for subscribing to peer discoverer | ||
func (t *TestPeerDiscoverer) Subscribe(ctx context.Context, ch <-chan PeerData) { | ||
go func() { | ||
for p := range ch { | ||
t.Lock() | ||
t.peerMap[p.AddrInfo.ID] = struct{}{} | ||
t.Unlock() | ||
} | ||
}() | ||
} | ||
|
||
// HasPeer is for checking if a peer is present in peer discoverer | ||
func (t *TestPeerDiscoverer) HasPeer(p peer.ID) bool { | ||
t.RLock() | ||
defer t.RUnlock() | ||
_, ok := t.peerMap[p] | ||
return ok | ||
} | ||
|
||
// PeerCount is for getting the number of peers in peer discoverer | ||
func (t *TestPeerDiscoverer) PeerCount() int { | ||
t.RLock() | ||
defer t.RUnlock() | ||
return len(t.peerMap) | ||
} | ||
|
||
// Clear is for clearing the peer discoverer | ||
func (t *TestPeerDiscoverer) Clear() { | ||
t.Lock() | ||
defer t.Unlock() | ||
t.peerMap = make(map[peer.ID]struct{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.