remove dtypes dependency from api; move NetBlockList type to api/types.go
This commit is contained in:
parent
2b68ba5f1d
commit
91e2530e11
@ -13,7 +13,6 @@ import (
|
||||
protocol "github.com/libp2p/go-libp2p-core/protocol"
|
||||
|
||||
"github.com/filecoin-project/lotus/build"
|
||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||
)
|
||||
|
||||
type Common interface {
|
||||
@ -48,9 +47,9 @@ type Common interface {
|
||||
NetBandwidthStatsByProtocol(ctx context.Context) (map[protocol.ID]metrics.Stats, error)
|
||||
|
||||
// ConnectionGater API
|
||||
NetBlockAdd(ctx context.Context, acl dtypes.NetBlockList) error
|
||||
NetBlockRemove(ctx context.Context, acl dtypes.NetBlockList) error
|
||||
NetBlockList(ctx context.Context) (dtypes.NetBlockList, error)
|
||||
NetBlockAdd(ctx context.Context, acl NetBlockList) error
|
||||
NetBlockRemove(ctx context.Context, acl NetBlockList) error
|
||||
NetBlockList(ctx context.Context) (NetBlockList, error)
|
||||
|
||||
// MethodGroup: Common
|
||||
|
||||
|
@ -60,9 +60,9 @@ type CommonStruct struct {
|
||||
NetBandwidthStatsByPeer func(ctx context.Context) (map[string]metrics.Stats, error) `perm:"read"`
|
||||
NetBandwidthStatsByProtocol func(ctx context.Context) (map[protocol.ID]metrics.Stats, error) `perm:"read"`
|
||||
NetAgentVersion func(ctx context.Context, p peer.ID) (string, error) `perm:"read"`
|
||||
NetBlockAdd func(ctx context.Context, acl dtypes.NetBlockList) error `perm:"admin"`
|
||||
NetBlockRemove func(ctx context.Context, acl dtypes.NetBlockList) error `perm:"admin"`
|
||||
NetBlockList func(ctx context.Context) (dtypes.NetBlockList, error) `perm:"read"`
|
||||
NetBlockAdd func(ctx context.Context, acl api.NetBlockList) error `perm:"admin"`
|
||||
NetBlockRemove func(ctx context.Context, acl api.NetBlockList) error `perm:"admin"`
|
||||
NetBlockList func(ctx context.Context) (api.NetBlockList, error) `perm:"read"`
|
||||
|
||||
ID func(context.Context) (peer.ID, error) `perm:"read"`
|
||||
Version func(context.Context) (api.Version, error) `perm:"read"`
|
||||
@ -498,15 +498,15 @@ func (c *CommonStruct) NetBandwidthStatsByProtocol(ctx context.Context) (map[pro
|
||||
return c.Internal.NetBandwidthStatsByProtocol(ctx)
|
||||
}
|
||||
|
||||
func (c *CommonStruct) NetBlockAdd(ctx context.Context, acl dtypes.NetBlockList) error {
|
||||
func (c *CommonStruct) NetBlockAdd(ctx context.Context, acl api.NetBlockList) error {
|
||||
return c.Internal.NetBlockAdd(ctx, acl)
|
||||
}
|
||||
|
||||
func (c *CommonStruct) NetBlockRemove(ctx context.Context, acl dtypes.NetBlockList) error {
|
||||
func (c *CommonStruct) NetBlockRemove(ctx context.Context, acl api.NetBlockList) error {
|
||||
return c.Internal.NetBlockRemove(ctx, acl)
|
||||
}
|
||||
|
||||
func (c *CommonStruct) NetBlockList(ctx context.Context) (dtypes.NetBlockList, error) {
|
||||
func (c *CommonStruct) NetBlockList(ctx context.Context) (api.NetBlockList, error) {
|
||||
return c.Internal.NetBlockList(ctx)
|
||||
}
|
||||
|
||||
|
@ -107,3 +107,9 @@ func NewDataTransferChannel(hostID peer.ID, channelState datatransfer.ChannelSta
|
||||
}
|
||||
return channel
|
||||
}
|
||||
|
||||
type NetBlockList struct {
|
||||
Peers []peer.ID
|
||||
IPAddrs []string
|
||||
IPSubnets []string
|
||||
}
|
||||
|
14
cli/net.go
14
cli/net.go
@ -18,9 +18,9 @@ import (
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
|
||||
atypes "github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/lib/addrutil"
|
||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||
)
|
||||
|
||||
var netCmd = &cli.Command{
|
||||
@ -420,7 +420,7 @@ var NetBlockAddPeer = &cli.Command{
|
||||
peers = append(peers, p)
|
||||
}
|
||||
|
||||
return api.NetBlockAdd(ctx, dtypes.NetBlockList{Peers: peers})
|
||||
return api.NetBlockAdd(ctx, atypes.NetBlockList{Peers: peers})
|
||||
},
|
||||
}
|
||||
|
||||
@ -436,7 +436,7 @@ var NetBlockAddIP = &cli.Command{
|
||||
defer closer()
|
||||
ctx := ReqContext(cctx)
|
||||
|
||||
return api.NetBlockAdd(ctx, dtypes.NetBlockList{IPAddrs: cctx.Args().Slice()})
|
||||
return api.NetBlockAdd(ctx, atypes.NetBlockList{IPAddrs: cctx.Args().Slice()})
|
||||
},
|
||||
}
|
||||
|
||||
@ -452,7 +452,7 @@ var NetBlockAddSubnet = &cli.Command{
|
||||
defer closer()
|
||||
ctx := ReqContext(cctx)
|
||||
|
||||
return api.NetBlockAdd(ctx, dtypes.NetBlockList{IPSubnets: cctx.Args().Slice()})
|
||||
return api.NetBlockAdd(ctx, atypes.NetBlockList{IPSubnets: cctx.Args().Slice()})
|
||||
},
|
||||
}
|
||||
|
||||
@ -488,7 +488,7 @@ var NetBlockRemovePeer = &cli.Command{
|
||||
peers = append(peers, p)
|
||||
}
|
||||
|
||||
return api.NetBlockRemove(ctx, dtypes.NetBlockList{Peers: peers})
|
||||
return api.NetBlockRemove(ctx, atypes.NetBlockList{Peers: peers})
|
||||
},
|
||||
}
|
||||
|
||||
@ -504,7 +504,7 @@ var NetBlockRemoveIP = &cli.Command{
|
||||
defer closer()
|
||||
ctx := ReqContext(cctx)
|
||||
|
||||
return api.NetBlockRemove(ctx, dtypes.NetBlockList{IPAddrs: cctx.Args().Slice()})
|
||||
return api.NetBlockRemove(ctx, atypes.NetBlockList{IPAddrs: cctx.Args().Slice()})
|
||||
},
|
||||
}
|
||||
|
||||
@ -520,7 +520,7 @@ var NetBlockRemoveSubnet = &cli.Command{
|
||||
defer closer()
|
||||
ctx := ReqContext(cctx)
|
||||
|
||||
return api.NetBlockRemove(ctx, dtypes.NetBlockList{IPSubnets: cctx.Args().Slice()})
|
||||
return api.NetBlockRemove(ctx, atypes.NetBlockList{IPSubnets: cctx.Args().Slice()})
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -9,12 +9,12 @@ import (
|
||||
logging "github.com/ipfs/go-log/v2"
|
||||
manet "github.com/multiformats/go-multiaddr/net"
|
||||
|
||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
)
|
||||
|
||||
var cLog = logging.Logger("conngater")
|
||||
|
||||
func (a *CommonAPI) NetBlockAdd(ctx context.Context, acl dtypes.NetBlockList) error {
|
||||
func (a *CommonAPI) NetBlockAdd(ctx context.Context, acl api.NetBlockList) error {
|
||||
for _, p := range acl.Peers {
|
||||
err := a.ConnGater.BlockPeer(p)
|
||||
if err != nil {
|
||||
@ -89,7 +89,7 @@ func (a *CommonAPI) NetBlockAdd(ctx context.Context, acl dtypes.NetBlockList) er
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *CommonAPI) NetBlockRemove(ctx context.Context, acl dtypes.NetBlockList) error {
|
||||
func (a *CommonAPI) NetBlockRemove(ctx context.Context, acl api.NetBlockList) error {
|
||||
for _, p := range acl.Peers {
|
||||
err := a.ConnGater.UnblockPeer(p)
|
||||
if err != nil {
|
||||
@ -124,7 +124,7 @@ func (a *CommonAPI) NetBlockRemove(ctx context.Context, acl dtypes.NetBlockList)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *CommonAPI) NetBlockList(ctx context.Context) (result dtypes.NetBlockList, err error) {
|
||||
func (a *CommonAPI) NetBlockList(ctx context.Context) (result api.NetBlockList, err error) {
|
||||
result.Peers = a.ConnGater.ListBlockedPeers()
|
||||
for _, ip := range a.ConnGater.ListBlockedAddrs() {
|
||||
result.IPAddrs = append(result.IPAddrs, ip.String())
|
||||
|
@ -1,11 +0,0 @@
|
||||
package dtypes
|
||||
|
||||
import (
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
)
|
||||
|
||||
type NetBlockList struct {
|
||||
Peers []peer.ID
|
||||
IPAddrs []string
|
||||
IPSubnets []string
|
||||
}
|
Loading…
Reference in New Issue
Block a user