-
Notifications
You must be signed in to change notification settings - Fork 376
/
extended_core_api.go
50 lines (41 loc) · 1.14 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
46
47
48
49
50
package ipfsutil
import (
ipfs_core "github.com/ipfs/go-ipfs/core"
ipfs_coreapi "github.com/ipfs/go-ipfs/core/coreapi"
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"
peer "github.com/libp2p/go-libp2p-core/peer"
)
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
ipfs_host.Host
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,
}
}
func NewExtendedCoreAPIFromNode(node *ipfs_core.IpfsNode) (ExtendedCoreAPI, error) {
api, err := ipfs_coreapi.NewCoreAPI(node)
if err != nil {
return nil, err
}
return NewExtendedCoreAPI(node.PeerHost, api), nil
}