diff --git a/app/submodule/network/network_api.go b/app/submodule/network/network_api.go index 755efc0d8e..ce5397485d 100644 --- a/app/submodule/network/network_api.go +++ b/app/submodule/network/network_api.go @@ -87,3 +87,8 @@ func (na *networkAPI) NetAddrsListen(context.Context) (peer.AddrInfo, error) { Addrs: na.network.Host.Addrs(), }, nil } + +// NetDisconnect disconnect to peer at the given address +func (na *networkAPI) NetDisconnect(_ context.Context, p peer.ID) error { + return na.network.Network.Disconnect(p) +} diff --git a/pkg/net/network.go b/pkg/net/network.go index 4fafdf0645..72b788121a 100644 --- a/pkg/net/network.go +++ b/pkg/net/network.go @@ -130,3 +130,8 @@ func (network *Network) Peers(ctx context.Context, verbose, latency, streams boo sort.Sort(&out) return &out, nil } + +// Disconnect disconnect to peer at the given address +func (network *Network) Disconnect(p peer.ID) error { + return network.host.Network().ClosePeer(p) +} diff --git a/venus-shared/api/chain/v0/method.md b/venus-shared/api/chain/v0/method.md index fb829b05fc..b7102f6a6c 100644 --- a/venus-shared/api/chain/v0/method.md +++ b/venus-shared/api/chain/v0/method.md @@ -127,6 +127,7 @@ * [MsigSwapPropose](#MsigSwapPropose) * [Network](#Network) * [NetAddrsListen](#NetAddrsListen) + * [NetDisconnect](#NetDisconnect) * [NetworkConnect](#NetworkConnect) * [NetworkFindPeer](#NetworkFindPeer) * [NetworkFindProvidersAsync](#NetworkFindProvidersAsync) @@ -4018,6 +4019,20 @@ Response: } ``` +### NetDisconnect + + +Perms: write + +Inputs: +```json +[ + "12D3KooWGzxzKZYveHXtpG6AsrUJBcWxHBFS2HsEoGTxrMLvKXtf" +] +``` + +Response: `{}` + ### NetworkConnect diff --git a/venus-shared/api/chain/v0/mock/mock_fullnode.go b/venus-shared/api/chain/v0/mock/mock_fullnode.go index 10200bb38c..971d6368d3 100644 --- a/venus-shared/api/chain/v0/mock/mock_fullnode.go +++ b/venus-shared/api/chain/v0/mock/mock_fullnode.go @@ -1149,6 +1149,20 @@ func (mr *MockFullNodeMockRecorder) NetAddrsListen(arg0 interface{}) *gomock.Cal return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NetAddrsListen", reflect.TypeOf((*MockFullNode)(nil).NetAddrsListen), arg0) } +// NetDisconnect mocks base method. +func (m *MockFullNode) NetDisconnect(arg0 context.Context, arg1 peer.ID) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NetDisconnect", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// NetDisconnect indicates an expected call of NetDisconnect. +func (mr *MockFullNodeMockRecorder) NetDisconnect(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NetDisconnect", reflect.TypeOf((*MockFullNode)(nil).NetDisconnect), arg0, arg1) +} + // NetworkConnect mocks base method. func (m *MockFullNode) NetworkConnect(arg0 context.Context, arg1 []string) (<-chan types.ConnectionResult, error) { m.ctrl.T.Helper() diff --git a/venus-shared/api/chain/v0/network.go b/venus-shared/api/chain/v0/network.go index 5a52ad38c1..e87c609da0 100644 --- a/venus-shared/api/chain/v0/network.go +++ b/venus-shared/api/chain/v0/network.go @@ -24,4 +24,5 @@ type INetwork interface { NetworkPing(context.Context, peer.ID) (time.Duration, error) //perm:read Version(context.Context) (types.Version, error) //perm:read NetAddrsListen(context.Context) (peer.AddrInfo, error) //perm:read + NetDisconnect(context.Context, peer.ID) error //perm:write } diff --git a/venus-shared/api/chain/v0/proxy_gen.go b/venus-shared/api/chain/v0/proxy_gen.go index 9e0bee8034..c5a6224aea 100644 --- a/venus-shared/api/chain/v0/proxy_gen.go +++ b/venus-shared/api/chain/v0/proxy_gen.go @@ -554,6 +554,7 @@ func (s *IMultiSigStruct) MsigSwapPropose(p0 context.Context, p1 address.Address type INetworkStruct struct { Internal struct { NetAddrsListen func(context.Context) (peer.AddrInfo, error) `perm:"read"` + NetDisconnect func(context.Context, peer.ID) error `perm:"write"` NetworkConnect func(ctx context.Context, addrs []string) (<-chan types.ConnectionResult, error) `perm:"read"` NetworkFindPeer func(ctx context.Context, peerID peer.ID) (peer.AddrInfo, error) `perm:"read"` NetworkFindProvidersAsync func(ctx context.Context, key cid.Cid, count int) <-chan peer.AddrInfo `perm:"read"` @@ -570,6 +571,9 @@ type INetworkStruct struct { func (s *INetworkStruct) NetAddrsListen(p0 context.Context) (peer.AddrInfo, error) { return s.Internal.NetAddrsListen(p0) } +func (s *INetworkStruct) NetDisconnect(p0 context.Context, p1 peer.ID) error { + return s.Internal.NetDisconnect(p0, p1) +} func (s *INetworkStruct) NetworkConnect(p0 context.Context, p1 []string) (<-chan types.ConnectionResult, error) { return s.Internal.NetworkConnect(p0, p1) } diff --git a/venus-shared/api/chain/v1/method.md b/venus-shared/api/chain/v1/method.md index 06d9804f8f..69ec0e9347 100644 --- a/venus-shared/api/chain/v1/method.md +++ b/venus-shared/api/chain/v1/method.md @@ -132,6 +132,7 @@ * [MsigSwapPropose](#MsigSwapPropose) * [Network](#Network) * [NetAddrsListen](#NetAddrsListen) + * [NetDisconnect](#NetDisconnect) * [NetworkConnect](#NetworkConnect) * [NetworkFindPeer](#NetworkFindPeer) * [NetworkFindProvidersAsync](#NetworkFindProvidersAsync) @@ -4409,6 +4410,20 @@ Response: } ``` +### NetDisconnect + + +Perms: write + +Inputs: +```json +[ + "12D3KooWGzxzKZYveHXtpG6AsrUJBcWxHBFS2HsEoGTxrMLvKXtf" +] +``` + +Response: `{}` + ### NetworkConnect diff --git a/venus-shared/api/chain/v1/mock/mock_fullnode.go b/venus-shared/api/chain/v1/mock/mock_fullnode.go index 97be391f25..b3e65e8088 100644 --- a/venus-shared/api/chain/v1/mock/mock_fullnode.go +++ b/venus-shared/api/chain/v1/mock/mock_fullnode.go @@ -1209,6 +1209,20 @@ func (mr *MockFullNodeMockRecorder) NetAddrsListen(arg0 interface{}) *gomock.Cal return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NetAddrsListen", reflect.TypeOf((*MockFullNode)(nil).NetAddrsListen), arg0) } +// NetDisconnect mocks base method. +func (m *MockFullNode) NetDisconnect(arg0 context.Context, arg1 peer.ID) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NetDisconnect", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// NetDisconnect indicates an expected call of NetDisconnect. +func (mr *MockFullNodeMockRecorder) NetDisconnect(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NetDisconnect", reflect.TypeOf((*MockFullNode)(nil).NetDisconnect), arg0, arg1) +} + // NetworkConnect mocks base method. func (m *MockFullNode) NetworkConnect(arg0 context.Context, arg1 []string) (<-chan types.ConnectionResult, error) { m.ctrl.T.Helper() diff --git a/venus-shared/api/chain/v1/network.go b/venus-shared/api/chain/v1/network.go index 1c7b10ff4f..113b71084f 100644 --- a/venus-shared/api/chain/v1/network.go +++ b/venus-shared/api/chain/v1/network.go @@ -24,4 +24,5 @@ type INetwork interface { NetworkPing(context.Context, peer.ID) (time.Duration, error) //perm:read Version(context.Context) (types.Version, error) //perm:read NetAddrsListen(context.Context) (peer.AddrInfo, error) //perm:read + NetDisconnect(context.Context, peer.ID) error //perm:write } diff --git a/venus-shared/api/chain/v1/proxy_gen.go b/venus-shared/api/chain/v1/proxy_gen.go index 5bf688444a..299b745031 100644 --- a/venus-shared/api/chain/v1/proxy_gen.go +++ b/venus-shared/api/chain/v1/proxy_gen.go @@ -574,6 +574,7 @@ func (s *IMultiSigStruct) MsigSwapPropose(p0 context.Context, p1 address.Address type INetworkStruct struct { Internal struct { NetAddrsListen func(context.Context) (peer.AddrInfo, error) `perm:"read"` + NetDisconnect func(context.Context, peer.ID) error `perm:"write"` NetworkConnect func(ctx context.Context, addrs []string) (<-chan types.ConnectionResult, error) `perm:"read"` NetworkFindPeer func(ctx context.Context, peerID peer.ID) (peer.AddrInfo, error) `perm:"read"` NetworkFindProvidersAsync func(ctx context.Context, key cid.Cid, count int) <-chan peer.AddrInfo `perm:"read"` @@ -590,6 +591,9 @@ type INetworkStruct struct { func (s *INetworkStruct) NetAddrsListen(p0 context.Context) (peer.AddrInfo, error) { return s.Internal.NetAddrsListen(p0) } +func (s *INetworkStruct) NetDisconnect(p0 context.Context, p1 peer.ID) error { + return s.Internal.NetDisconnect(p0, p1) +} func (s *INetworkStruct) NetworkConnect(p0 context.Context, p1 []string) (<-chan types.ConnectionResult, error) { return s.Internal.NetworkConnect(p0, p1) } diff --git a/venus-shared/compatible-checks/api-diff.txt b/venus-shared/compatible-checks/api-diff.txt index db7f03492e..d9ff4007ec 100644 --- a/venus-shared/compatible-checks/api-diff.txt +++ b/venus-shared/compatible-checks/api-diff.txt @@ -95,7 +95,6 @@ github.com/filecoin-project/venus/venus-shared/api/chain/v0.FullNode <> github.c - NetBlockRemove - NetConnect - NetConnectedness - - NetDisconnect - NetFindPeer - NetLimit - NetPeerInfo @@ -296,7 +295,6 @@ github.com/filecoin-project/venus/venus-shared/api/chain/v1.FullNode <> github.c - NetBlockRemove - NetConnect - NetConnectedness - - NetDisconnect - NetFindPeer - NetLimit - NetPeerInfo diff --git a/venus-shared/compatible-checks/api-perm.txt b/venus-shared/compatible-checks/api-perm.txt index af7a5e87f5..cba9a4f8c0 100644 --- a/venus-shared/compatible-checks/api-perm.txt +++ b/venus-shared/compatible-checks/api-perm.txt @@ -21,6 +21,7 @@ v0: github.com/filecoin-project/venus/venus-shared/api/chain/v0 <> github.com/fi - IMessagePool.MpoolSelects - IMultiSig.MsigCancelTxnHash - INetwork.NetAddrsListen + - INetwork.NetDisconnect - INetwork.NetworkConnect - INetwork.NetworkFindPeer - INetwork.NetworkFindProvidersAsync