2019-11-01 12:01:16 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
2020-10-17 10:53:42 +00:00
|
|
|
"github.com/google/uuid"
|
|
|
|
|
2020-08-18 01:12:50 +00:00
|
|
|
"github.com/filecoin-project/go-jsonrpc/auth"
|
2020-09-02 22:25:53 +00:00
|
|
|
metrics "github.com/libp2p/go-libp2p-core/metrics"
|
2019-11-01 12:01:16 +00:00
|
|
|
"github.com/libp2p/go-libp2p-core/network"
|
|
|
|
"github.com/libp2p/go-libp2p-core/peer"
|
2020-09-02 23:31:41 +00:00
|
|
|
protocol "github.com/libp2p/go-libp2p-core/protocol"
|
2020-05-20 18:23:51 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/build"
|
|
|
|
)
|
2019-12-09 17:08:32 +00:00
|
|
|
|
2019-11-01 12:01:16 +00:00
|
|
|
type Common interface {
|
2020-06-18 12:56:00 +00:00
|
|
|
|
|
|
|
// MethodGroup: Auth
|
|
|
|
|
2020-05-20 18:23:51 +00:00
|
|
|
AuthVerify(ctx context.Context, token string) ([]auth.Permission, error)
|
|
|
|
AuthNew(ctx context.Context, perms []auth.Permission) ([]byte, error)
|
2019-11-01 12:01:16 +00:00
|
|
|
|
2020-06-18 12:56:00 +00:00
|
|
|
// MethodGroup: Net
|
2019-11-01 12:01:16 +00:00
|
|
|
|
|
|
|
NetConnectedness(context.Context, peer.ID) (network.Connectedness, error)
|
|
|
|
NetPeers(context.Context) ([]peer.AddrInfo, error)
|
|
|
|
NetConnect(context.Context, peer.AddrInfo) error
|
|
|
|
NetAddrsListen(context.Context) (peer.AddrInfo, error)
|
|
|
|
NetDisconnect(context.Context, peer.ID) error
|
2020-02-18 19:09:00 +00:00
|
|
|
NetFindPeer(context.Context, peer.ID) (peer.AddrInfo, error)
|
2020-06-03 01:13:49 +00:00
|
|
|
NetPubsubScores(context.Context) ([]PubsubScore, error)
|
2020-08-13 11:18:14 +00:00
|
|
|
NetAutoNatStatus(context.Context) (NatInfo, error)
|
2020-09-03 23:35:53 +00:00
|
|
|
NetAgentVersion(ctx context.Context, p peer.ID) (string, error)
|
2021-03-06 17:14:13 +00:00
|
|
|
NetPeerInfo(context.Context, peer.ID) (*ExtendedPeerInfo, error)
|
2020-09-02 22:45:57 +00:00
|
|
|
|
|
|
|
// NetBandwidthStats returns statistics about the nodes total bandwidth
|
|
|
|
// usage and current rate across all peers and protocols.
|
2020-09-02 22:25:53 +00:00
|
|
|
NetBandwidthStats(ctx context.Context) (metrics.Stats, error)
|
2020-09-02 22:45:57 +00:00
|
|
|
|
|
|
|
// NetBandwidthStatsByPeer returns statistics about the nodes bandwidth
|
|
|
|
// usage and current rate per peer
|
2020-09-02 22:25:53 +00:00
|
|
|
NetBandwidthStatsByPeer(ctx context.Context) (map[string]metrics.Stats, error)
|
2020-09-02 22:45:57 +00:00
|
|
|
|
|
|
|
// NetBandwidthStatsByProtocol returns statistics about the nodes bandwidth
|
|
|
|
// usage and current rate per protocol
|
2020-09-02 22:25:53 +00:00
|
|
|
NetBandwidthStatsByProtocol(ctx context.Context) (map[protocol.ID]metrics.Stats, error)
|
2019-11-01 12:01:16 +00:00
|
|
|
|
2020-11-13 10:17:20 +00:00
|
|
|
// ConnectionGater API
|
2020-11-13 19:11:17 +00:00
|
|
|
NetBlockAdd(ctx context.Context, acl NetBlockList) error
|
|
|
|
NetBlockRemove(ctx context.Context, acl NetBlockList) error
|
|
|
|
NetBlockList(ctx context.Context) (NetBlockList, error)
|
2020-11-13 10:17:20 +00:00
|
|
|
|
2020-06-18 12:56:00 +00:00
|
|
|
// MethodGroup: Common
|
|
|
|
|
2019-11-01 12:01:16 +00:00
|
|
|
// ID returns peerID of libp2p node backing this API
|
|
|
|
ID(context.Context) (peer.ID, error)
|
|
|
|
|
|
|
|
// Version provides information about API provider
|
|
|
|
Version(context.Context) (Version, error)
|
2020-02-15 05:49:54 +00:00
|
|
|
|
|
|
|
LogList(context.Context) ([]string, error)
|
|
|
|
LogSetLevel(context.Context, string, string) error
|
2020-06-02 18:54:24 +00:00
|
|
|
|
|
|
|
// trigger graceful shutdown
|
|
|
|
Shutdown(context.Context) error
|
2020-06-17 14:44:59 +00:00
|
|
|
|
2020-10-17 10:53:42 +00:00
|
|
|
// Session returns a random UUID of api provider session
|
|
|
|
Session(context.Context) (uuid.UUID, error)
|
|
|
|
|
2020-06-17 14:44:59 +00:00
|
|
|
Closing(context.Context) (<-chan struct{}, error)
|
2019-11-01 12:01:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Version provides various build-time information
|
|
|
|
type Version struct {
|
|
|
|
Version string
|
|
|
|
|
|
|
|
// APIVersion is a binary encoded semver version of the remote implementing
|
|
|
|
// this api
|
|
|
|
//
|
|
|
|
// See APIVersion in build/version.go
|
2019-12-17 15:26:16 +00:00
|
|
|
APIVersion build.Version
|
2019-11-01 12:01:16 +00:00
|
|
|
|
|
|
|
// TODO: git commit / os / genesis cid?
|
|
|
|
|
|
|
|
// Seconds
|
|
|
|
BlockDelay uint64
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v Version) String() string {
|
2019-12-17 15:26:16 +00:00
|
|
|
return fmt.Sprintf("%s+api%s", v.Version, v.APIVersion.String())
|
2019-11-01 13:58:48 +00:00
|
|
|
}
|
2020-08-13 11:18:14 +00:00
|
|
|
|
|
|
|
type NatInfo struct {
|
|
|
|
Reachability network.Reachability
|
2020-08-18 01:12:50 +00:00
|
|
|
PublicAddr string
|
2020-08-13 11:18:14 +00:00
|
|
|
}
|