Skip to content

Commit

Permalink
add net commands (#614)
Browse files Browse the repository at this point in the history
* add net commands and methods

* docsgen

* fix lint errors. change dtypes.ScoreKeeper

* fix lint error. Switch to lotus scorekeeper

* fix lint errors

* Add Net command to main

* refactor: import lotus net implementation instead of copying it

* refactor: copy ResourceManager from lotus modules

* refactor: lowercase NetCmd

Co-authored-by: Dirk McCormick <dirkmdev@gmail.com>
  • Loading branch information
LexLuthr and dirkmc authored Jun 28, 2022
1 parent 85d1357 commit ad6ad3d
Show file tree
Hide file tree
Showing 12 changed files with 629 additions and 345 deletions.
46 changes: 29 additions & 17 deletions api/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package api

import (
"context"
"time"

lotus_api "github.com/filecoin-project/lotus/api"
lotus_net "github.com/filecoin-project/lotus/node/impl/net"
metrics "github.com/libp2p/go-libp2p-core/metrics"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
Expand All @@ -20,18 +23,22 @@ import (
// * Generate markdown docs
// * Generate openrpc blobs

// This interface is a direct copy of the lotus equivalent.
// We can't just include the lotus equivalent directly because of the way that
// the generator works (it doesn't pull in types that are outside this directory)
type Net interface {
// MethodGroup: Net
NetConnectedness(context.Context, peer.ID) (network.Connectedness, error) //perm:read
NetPeers(context.Context) ([]peer.AddrInfo, error) //perm:read
NetConnect(context.Context, peer.AddrInfo) error //perm:write
NetAddrsListen(context.Context) (peer.AddrInfo, error) //perm:read
NetDisconnect(context.Context, peer.ID) error //perm:write
NetFindPeer(context.Context, peer.ID) (peer.AddrInfo, error) //perm:read
//NetPubsubScores(context.Context) ([]PubsubScore, error) //perm:read
NetAutoNatStatus(context.Context) (NatInfo, error) //perm:read
NetAgentVersion(ctx context.Context, p peer.ID) (string, error) //perm:read
NetPeerInfo(context.Context, peer.ID) (*ExtendedPeerInfo, error) //perm:read
NetConnectedness(context.Context, peer.ID) (network.Connectedness, error) //perm:read
NetPeers(context.Context) ([]peer.AddrInfo, error) //perm:read
NetPing(context.Context, peer.ID) (time.Duration, error) //perm:read
NetConnect(context.Context, peer.AddrInfo) error //perm:write
NetAddrsListen(context.Context) (peer.AddrInfo, error) //perm:read
NetDisconnect(context.Context, peer.ID) error //perm:write
NetFindPeer(context.Context, peer.ID) (peer.AddrInfo, error) //perm:read
NetPubsubScores(context.Context) ([]lotus_api.PubsubScore, error) //perm:read
NetAutoNatStatus(context.Context) (lotus_api.NatInfo, error) //perm:read
NetAgentVersion(ctx context.Context, p peer.ID) (string, error) //perm:read
NetPeerInfo(context.Context, peer.ID) (*lotus_api.ExtendedPeerInfo, error) //perm:read

// NetBandwidthStats returns statistics about the nodes total bandwidth
// usage and current rate across all peers and protocols.
Expand All @@ -46,20 +53,25 @@ type Net interface {
NetBandwidthStatsByProtocol(ctx context.Context) (map[protocol.ID]metrics.Stats, error) //perm:read

// ConnectionGater API
NetBlockAdd(ctx context.Context, acl NetBlockList) error //perm:admin
NetBlockRemove(ctx context.Context, acl NetBlockList) error //perm:admin
NetBlockList(ctx context.Context) (NetBlockList, error) //perm:read
NetBlockAdd(ctx context.Context, acl lotus_api.NetBlockList) error //perm:admin
NetBlockRemove(ctx context.Context, acl lotus_api.NetBlockList) error //perm:admin
NetBlockList(ctx context.Context) (lotus_api.NetBlockList, error) //perm:read
NetProtectAdd(ctx context.Context, acl []peer.ID) error //perm:admin
NetProtectRemove(ctx context.Context, acl []peer.ID) error //perm:admin
NetProtectList(ctx context.Context) ([]peer.ID, error) //perm:read

// ID returns peerID of libp2p node backing this API
ID(context.Context) (peer.ID, error) //perm:read

// ResourceManager API
NetStat(ctx context.Context, scope string) (lotus_api.NetStat, error) //perm:read
NetLimit(ctx context.Context, scope string) (lotus_api.NetLimit, error) //perm:read
NetSetLimit(ctx context.Context, scope string, limit lotus_api.NetLimit) error //perm:admin
}

type CommonNet interface {
Common
Net
}

type NatInfo struct {
Reachability network.Reachability
PublicAddr string
}
var _ Net = (*lotus_net.NetAPI)(nil)
144 changes: 125 additions & 19 deletions api/proxy_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,6 @@ func NewDataTransferChannel(hostID peer.ID, channelState datatransfer.ChannelSta
return channel
}

type NetBlockList struct {
Peers []peer.ID
IPAddrs []string
IPSubnets []string
}

type ExtendedPeerInfo struct {
ID peer.ID
Agent string
Expand Down
Binary file modified build/openrpc/boost.json.gz
Binary file not shown.
1 change: 1 addition & 0 deletions cmd/boostd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func main() {
logCmd,
dagstoreCmd,
piecesCmd,
netCmd,
},
}
app.Setup()
Expand Down
17 changes: 17 additions & 0 deletions cmd/boostd/net.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package main

import (
"github.com/filecoin-project/boost/node"
lcli "github.com/filecoin-project/lotus/cli"
"github.com/urfave/cli/v2"
)

var netCmd = &cli.Command{
Name: "net",
Usage: "Manage P2P Network",
Before: func(cctx *cli.Context) error {
cctx.App.Metadata["repoType"] = node.Boost
return nil
},
Subcommands: lcli.NetCmd.Subcommands,
}
Loading

0 comments on commit ad6ad3d

Please sign in to comment.