lotus/node/api.go

53 lines
1.0 KiB
Go
Raw Normal View History

2019-07-08 19:07:16 +00:00
package node
import (
"context"
2019-07-08 19:07:16 +00:00
"github.com/filecoin-project/go-lotus/api"
"github.com/filecoin-project/go-lotus/build"
"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/peer"
2019-07-08 21:01:15 +00:00
ma "github.com/multiformats/go-multiaddr"
2019-07-08 19:07:16 +00:00
)
2019-07-09 10:58:13 +00:00
type API struct {
Host host.Host
2019-07-08 19:07:16 +00:00
}
2019-07-09 10:58:13 +00:00
func (a *API) ID(context.Context) (peer.ID, error) {
return a.Host.ID(), nil
2019-07-08 19:07:16 +00:00
}
2019-07-09 10:58:13 +00:00
func (a *API) Version(context.Context) (api.Version, error) {
return api.Version{
Version: build.Version,
}, nil
2019-07-08 19:07:16 +00:00
}
2019-07-09 10:58:13 +00:00
func (a *API) NetPeers(context.Context) ([]peer.AddrInfo, error) {
conns := a.Host.Network().Conns()
out := make([]peer.AddrInfo, len(conns))
2019-07-08 19:07:16 +00:00
2019-07-09 10:58:13 +00:00
for i, conn := range conns {
out[i] = peer.AddrInfo{
ID: conn.RemotePeer(),
Addrs: []ma.Multiaddr{
conn.RemoteMultiaddr(),
},
2019-07-08 19:07:16 +00:00
}
}
2019-07-09 10:58:13 +00:00
return out, nil
2019-07-08 19:07:16 +00:00
}
2019-07-09 10:58:13 +00:00
func (a *API) NetConnect(ctx context.Context, p peer.AddrInfo) error {
return a.Host.Connect(ctx, p)
2019-07-08 19:07:16 +00:00
}
2019-07-08 21:01:15 +00:00
func (a *API) NetAddrsListen(context.Context) (api.MultiaddrSlice, error) {
2019-07-09 10:58:13 +00:00
return a.Host.Addrs(), nil
2019-07-08 21:01:15 +00:00
}
2019-07-09 10:58:13 +00:00
var _ api.API = &API{}