mirror of
https://github.com/status-im/status-go.git
synced 2025-02-16 16:56:53 +00:00
advancing with the px test
This commit is contained in:
parent
10936f6337
commit
c744d59fee
@ -216,6 +216,10 @@ package wakuv2
|
||||
WAKU_CALL (waku_relay_get_num_connected_peers(ctx, pubSubTopic, (WakuCallBack) callback, resp) );
|
||||
}
|
||||
|
||||
static void cGoWakuGetPeerIdsFromPeerStore(void* wakuCtx, void* resp) {
|
||||
WAKU_CALL (waku_get_peerids_from_peerstore(wakuCtx, (WakuCallBack) callback, resp) );
|
||||
}
|
||||
|
||||
static void cGoWakuLightpushPublish(void* wakuCtx,
|
||||
const char* pubSubTopic,
|
||||
const char* jsonWakuMessage,
|
||||
@ -2282,6 +2286,36 @@ func (self *Waku) GetNumConnectedPeers(paramPubsubTopic ...string) (int, error)
|
||||
return 0, errors.New(errMsg)
|
||||
}
|
||||
|
||||
func (self *Waku) GetPeerIdsFromPeerStore() (peer.IDSlice, error) {
|
||||
var resp = C.allocResp()
|
||||
defer C.freeResp(resp)
|
||||
C.cGoWakuGetPeerIdsFromPeerStore(self.wakuCtx, resp)
|
||||
|
||||
if C.getRet(resp) == C.RET_OK {
|
||||
peersStr := C.GoStringN(C.getMyCharPtr(resp), C.int(C.getMyCharLen(resp)))
|
||||
if peersStr == "" {
|
||||
return peer.IDSlice{}, nil
|
||||
}
|
||||
// peersStr contains a comma-separated list of peer ids
|
||||
itemsPeerIds := strings.Split(peersStr, ",")
|
||||
|
||||
var peers peer.IDSlice
|
||||
for _, peer := range itemsPeerIds {
|
||||
id, err := peermod.Decode(peer)
|
||||
if err != nil {
|
||||
errMsg := "GetPeerIdsFromPeerStore - error decoding peerId: " + err.Error()
|
||||
return nil, errors.New(errMsg)
|
||||
}
|
||||
peers = append(peers, id)
|
||||
}
|
||||
|
||||
return peers, nil
|
||||
}
|
||||
errMsg := "error GetPeerIdsFromPeerStore: " +
|
||||
C.GoStringN(C.getMyCharPtr(resp), C.int(C.getMyCharLen(resp)))
|
||||
return nil, errors.New(errMsg)
|
||||
}
|
||||
|
||||
func (self *Waku) GetPeerIdsByProtocol(protocol string) (peer.IDSlice, error) {
|
||||
var resp = C.allocResp()
|
||||
var cProtocol = C.CString(protocol)
|
||||
@ -2302,7 +2336,7 @@ func (self *Waku) GetPeerIdsByProtocol(protocol string) (peer.IDSlice, error) {
|
||||
for _, peer := range itemsPeerIds {
|
||||
id, err := peermod.Decode(peer)
|
||||
if err != nil {
|
||||
errMsg := "GetPeerIdsByProtocol - error converting string to int: " + err.Error()
|
||||
errMsg := "GetPeerIdsByProtocol - error decoding peerId: " + err.Error()
|
||||
return nil, errors.New(errMsg)
|
||||
}
|
||||
peers = append(peers, id)
|
||||
|
@ -350,6 +350,8 @@ func TestPeerExchange(t *testing.T) {
|
||||
require.NotNil(t, enr)
|
||||
|
||||
ma, err := pxServerNode.ListenAddresses()
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, ma)
|
||||
|
||||
// start node that will be discovered by PeerExchange
|
||||
discV5NodeConfig := WakuConfig{
|
||||
@ -371,8 +373,7 @@ func TestPeerExchange(t *testing.T) {
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
// start light node which use PeerExchange to discover peers
|
||||
|
||||
// start light node which use PeerExchange to discover peers
|
||||
pxClientConfig := WakuConfig{
|
||||
// Port: 30303,
|
||||
// NodeKey: "11d0dcea28e86f81937a3bd1163473c7fbc0a0db54fd72914849bc47bdf78710",
|
||||
@ -381,15 +382,33 @@ func TestPeerExchange(t *testing.T) {
|
||||
Discv5Discovery: false,
|
||||
ClusterID: 16,
|
||||
Shards: []uint16{64},
|
||||
PeerExchange: false,
|
||||
PeerExchange: true,
|
||||
Discv5UdpPort: 9002,
|
||||
PeerExchangeNode: "", // TODO: fill
|
||||
PeerExchangeNode: ma[0].String(),
|
||||
}
|
||||
|
||||
lightNode, err := New(nil, "", &pxClientConfig, logger.Named("lightNode"), nil, nil, nil, nil)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, lightNode.Start())
|
||||
|
||||
// Sanity check, not great, but it's probably helpful
|
||||
options := func(b *backoff.ExponentialBackOff) {
|
||||
b.MaxElapsedTime = 30 * time.Second
|
||||
}
|
||||
|
||||
err = tt.RetryWithBackOff(func() error {
|
||||
peers, err := lightNode.GetPeerIdsFromPeerStore()
|
||||
fmt.Println("------------ peers: ", peers)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(peers) == 2 {
|
||||
return nil
|
||||
}
|
||||
return errors.New("no peers discovered")
|
||||
}, options)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NoError(t, lightNode.Stop())
|
||||
require.NoError(t, pxServerNode.Stop())
|
||||
require.NoError(t, discV5Node.Stop())
|
||||
|
Loading…
x
Reference in New Issue
Block a user