-
Notifications
You must be signed in to change notification settings - Fork 199
/
libp2pContext.go
47 lines (38 loc) · 1.01 KB
/
libp2pContext.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
package libp2p
import (
"context"
"github.com/ElrondNetwork/elrond-go/p2p"
)
// Libp2pContext holds the context for the wrappers over libp2p implementation
type Libp2pContext struct {
ctx context.Context
connHost ConnectableHost
}
// NewLibp2pContext constructs a new Libp2pContext object
func NewLibp2pContext(ctx context.Context, connHost ConnectableHost) (*Libp2pContext, error) {
if ctx == nil {
return nil, p2p.ErrNilContext
}
if connHost == nil || connHost.IsInterfaceNil() {
return nil, p2p.ErrNilHost
}
return &Libp2pContext{
ctx: ctx,
connHost: connHost,
}, nil
}
// Context returns the context associated with this struct
func (lctx *Libp2pContext) Context() context.Context {
return lctx.ctx
}
// Host returns the connectable host
func (lctx *Libp2pContext) Host() ConnectableHost {
return lctx.connHost
}
// IsInterfaceNil returns true if there is no value under the interface
func (lctx *Libp2pContext) IsInterfaceNil() bool {
if lctx == nil {
return true
}
return false
}