adding dialing to test

This commit is contained in:
Gabriel mermelstein 2024-10-11 17:40:45 +03:00
parent ba45cbc8cc
commit 0b5e20b00a
No known key found for this signature in database
GPG Key ID: 82B8134785FEAE0D
2 changed files with 48 additions and 11 deletions

View File

@ -182,6 +182,20 @@ package wakuv2
resp) );
}
static void cGoWakuDialPeerById(void* wakuCtx,
char* peerId,
char* protocol,
int timeoutMs,
void* resp) {
WAKU_CALL( waku_dial_peer_by_id(wakuCtx,
peerId,
protocol,
timeoutMs,
(WakuCallBack) callback,
resp) );
}
static void cGoWakuDisconnectPeerById(void* wakuCtx, char* peerId, void* resp) {
WAKU_CALL( waku_disconnect_peer_by_id(wakuCtx,
peerId,
@ -300,6 +314,7 @@ import (
"github.com/waku-org/go-waku/waku/v2/protocol"
"github.com/waku-org/go-waku/waku/v2/protocol/legacy_store"
"github.com/waku-org/go-waku/waku/v2/protocol/pb"
"github.com/waku-org/go-waku/waku/v2/protocol/relay"
"github.com/waku-org/go-waku/waku/v2/protocol/store"
storepb "github.com/waku-org/go-waku/waku/v2/protocol/store/pb"
"github.com/waku-org/go-waku/waku/v2/utils"
@ -1558,11 +1573,8 @@ func (w *Waku) DialPeer(address multiaddr.Multiaddr) error {
return nil
}
func (w *Waku) DialPeerByID(peerID peer.ID) error {
// ctx, cancel := context.WithTimeout(w.ctx, requestTimeout)
// defer cancel()
// return w.node.DialPeerByID(ctx, peerID)
return nil
func (w *Waku) DialPeerByID(peerId peer.ID) error {
return w.WakuDialPeerById(peerId, string(relay.WakuRelayID_v200), 1000)
}
func (w *Waku) DropPeer(peerID peer.ID) error {
@ -2170,6 +2182,24 @@ func (self *Waku) WakuConnect(peerMultiAddr string, timeoutMs int) error {
return errors.New(errMsg)
}
func (self *Waku) WakuDialPeerById(peerId peer.ID, protocol string, timeoutMs int) error {
var resp = C.allocResp()
var cPeerId = C.CString(peerId.String())
var cProtocol = C.CString(protocol)
defer C.freeResp(resp)
defer C.free(unsafe.Pointer(cPeerId))
defer C.free(unsafe.Pointer(cProtocol))
C.cGoWakuDialPeerById(self.wakuCtx, cPeerId, cProtocol, C.int(timeoutMs), resp)
if C.getRet(resp) == C.RET_OK {
return nil
}
errMsg := "error DialPeerById: " +
C.GoStringN(C.getMyCharPtr(resp), C.int(C.getMyCharLen(resp)))
return errors.New(errMsg)
}
func (self *Waku) ListenAddresses() ([]multiaddr.Multiaddr, error) {
var resp = C.allocResp()
defer C.freeResp(resp)

View File

@ -153,12 +153,11 @@ func parseNodes(rec []string) []*enode.Node {
//
// Using Docker:
//
// IP_ADDRESS=$(ipconfig getifaddr en0)
// IP_ADDRESS=$(hostname -I | awk '{print $1}');
// docker run \
// -p 61000:61000/tcp -p 8000:8000/udp -p 8646:8646/tcp harbor.status.im/wakuorg/nwaku:v0.33.0 \
// --discv5-discovery=true --cluster-id=16 --log-level=DEBUG \
// --nat=extip:${IP_ADDRESS} --discv5-discovery --discv5-udp-port=8000 --rest-address=0.0.0.0 --store --rest-port=8646 \
// --tcp-port=61000 --rest-admin=true --shard=64 --dns-discovery=true --dns-discovery-url="/dns4/boot-01.do-ams3.status.prod.status.im/tcp/30303/p2p/16Uiu2HAmAR24Mbb6VuzoyUiGx42UenDkshENVDj4qnmmbabLvo31"
func TestBasicWakuV2(t *testing.T) {
extNodeRestPort := 8646
@ -211,6 +210,7 @@ func TestBasicWakuV2(t *testing.T) {
require.NoError(t, err)
connectedStoreNodes, err := w.GetPeerIdsByProtocol(string(store.StoreQueryID_v300))
require.NoError(t, err)
require.True(t, slices.Contains(connectedStoreNodes, storeNode.ID), "nwaku should be connected to the store node")
err = w.DisconnectPeerById(storeNode.ID)
@ -221,6 +221,13 @@ func TestBasicWakuV2(t *testing.T) {
isDisconnected := !slices.Contains(connectedStoreNodes, storeNode.ID)
require.True(t, isDisconnected, "nwaku should be disconnected from the store node")
err = w.DialPeerByID(storeNode.ID)
require.NoError(t, err)
connectedStoreNodes, err = w.GetPeerIdsByProtocol(string(store.StoreQueryID_v300))
require.NoError(t, err)
require.True(t, slices.Contains(connectedStoreNodes, storeNode.ID), "nwaku should be connected to the store node")
/* // Dropping Peer
err = w.DropPeer(storeNode.PeerID)
require.NoError(t, err)