-
Notifications
You must be signed in to change notification settings - Fork 376
/
extended_core_api.go
45 lines (37 loc) · 1.1 KB
/
extended_core_api.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
package ipfsutil
import (
"context"
ipfs_interface "github.com/ipfs/interface-go-ipfs-core"
"github.com/libp2p/go-libp2p-core/connmgr"
ipfs_host "github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/network"
peer "github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/protocol"
)
type ConnMgr interface {
TagPeer(peer.ID, string, int)
UntagPeer(p peer.ID, tag string)
Protect(id peer.ID, tag string)
Unprotect(id peer.ID, tag string) (protected bool)
GetTagInfo(p peer.ID) *connmgr.TagInfo
}
type ExtendedCoreAPI interface {
ipfs_interface.CoreAPI
NewStream(ctx context.Context, p peer.ID, pids ...protocol.ID) (network.Stream, error)
SetStreamHandler(pid protocol.ID, handler network.StreamHandler)
RemoveStreamHandler(pid protocol.ID)
ConnMgr() ConnMgr
}
type extendedCoreAPI struct {
ipfs_interface.CoreAPI
ipfs_host.Host
}
func (e *extendedCoreAPI) ConnMgr() ConnMgr {
return e.Host.ConnManager()
}
func NewExtendedCoreAPI(host ipfs_host.Host, api ipfs_interface.CoreAPI) ExtendedCoreAPI {
return &extendedCoreAPI{
CoreAPI: api,
Host: host,
}
}