-
Notifications
You must be signed in to change notification settings - Fork 199
/
options.go
49 lines (41 loc) · 1.08 KB
/
options.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
package libp2p
import (
"time"
"github.com/ElrondNetwork/elrond-go-core/core/check"
"github.com/ElrondNetwork/elrond-go/p2p"
)
var readTimeout = time.Second * 10
// Option represents a functional configuration parameter that can operate
// over the networkMessenger struct.
type Option func(*networkMessenger) error
// WithAuthentication sets up the authentication mechanism and peer id - public key collection
func WithAuthentication(
networkShardingCollector p2p.NetworkShardingCollector,
signerVerifier p2p.SignerVerifier,
marshalizer p2p.Marshalizer,
) Option {
return func(mes *networkMessenger) error {
if check.IfNil(networkShardingCollector) {
return p2p.ErrNilNetworkShardingCollector
}
if check.IfNil(signerVerifier) {
return p2p.ErrNilSignerVerifier
}
if check.IfNil(marshalizer) {
return p2p.ErrNilMarshalizer
}
var err error
mes.ip, err = NewIdentityProvider(
mes.p2pHost,
networkShardingCollector,
signerVerifier,
marshalizer,
readTimeout,
)
if err != nil {
return err
}
mes.p2pHost.Network().Notify(mes.ip)
return nil
}
}