-
Notifications
You must be signed in to change notification settings - Fork 199
/
connStub.go
84 lines (69 loc) · 1.87 KB
/
connStub.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package mock
import (
"context"
libp2pCrypto "github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/multiformats/go-multiaddr"
)
// ConnStub -
type ConnStub struct {
IDCalled func() string
CloseCalled func() error
LocalPeerCalled func() peer.ID
LocalPrivateKeyCalled func() libp2pCrypto.PrivKey
RemotePeerCalled func() peer.ID
RemotePublicKeyCalled func() libp2pCrypto.PubKey
LocalMultiaddrCalled func() multiaddr.Multiaddr
RemoteMultiaddrCalled func() multiaddr.Multiaddr
NewStreamCalled func(ctx context.Context) (network.Stream, error)
GetStreamsCalled func() []network.Stream
StatCalled func() network.Stat
}
// ID -
func (cs *ConnStub) ID() string {
if cs.IDCalled != nil {
return cs.IDCalled()
}
return ""
}
// Close -
func (cs *ConnStub) Close() error {
return cs.CloseCalled()
}
// LocalPeer -
func (cs *ConnStub) LocalPeer() peer.ID {
return cs.LocalPeerCalled()
}
// LocalPrivateKey -
func (cs *ConnStub) LocalPrivateKey() libp2pCrypto.PrivKey {
return cs.LocalPrivateKeyCalled()
}
// RemotePeer -
func (cs *ConnStub) RemotePeer() peer.ID {
return cs.RemotePeerCalled()
}
// RemotePublicKey -
func (cs *ConnStub) RemotePublicKey() libp2pCrypto.PubKey {
return cs.RemotePublicKeyCalled()
}
// LocalMultiaddr -
func (cs *ConnStub) LocalMultiaddr() multiaddr.Multiaddr {
return cs.LocalMultiaddrCalled()
}
// RemoteMultiaddr -
func (cs *ConnStub) RemoteMultiaddr() multiaddr.Multiaddr {
return cs.RemoteMultiaddrCalled()
}
// NewStream -
func (cs *ConnStub) NewStream(ctx context.Context) (network.Stream, error) {
return cs.NewStreamCalled(ctx)
}
// GetStreams -
func (cs *ConnStub) GetStreams() []network.Stream {
return cs.GetStreamsCalled()
}
// Stat -
func (cs *ConnStub) Stat() network.Stat {
return cs.StatCalled()
}