Skip to content

Commit

Permalink
chore_: uncomment code that would allow status-go/go-waku to compile …
Browse files Browse the repository at this point in the history
…and libwaku test to run (#5986)
  • Loading branch information
richard-ramos authored Oct 24, 2024
1 parent 6dd9b20 commit ed5a9aa
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 39 deletions.
12 changes: 10 additions & 2 deletions timesource/timesource.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ func (s *NTPTimeSource) Stop() {
}

func (s *NTPTimeSource) GetCurrentTime() time.Time {
s.Start(context.Background())
err := s.Start(context.Background())
if err != nil {
panic("could not obtain timesource")
}

return s.Now()
}

Expand All @@ -249,7 +253,11 @@ func (s *NTPTimeSource) GetCurrentTimeInMillis() uint64 {

func GetCurrentTime() time.Time {
ts := Default()
ts.Start(context.Background())
err := ts.Start(context.Background())
if err != nil {
panic("could not obtain timesource")
}

return ts.Now()
}

Expand Down
3 changes: 2 additions & 1 deletion timesource/timesource_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package timesource

import (
"context"
"errors"
"sync"
"testing"
Expand Down Expand Up @@ -214,7 +215,7 @@ func TestRunningPeriodically(t *testing.T) {
// on NTPTimeSource specified periods (fastNTPSyncPeriod & slowNTPSyncPeriod)
wg := sync.WaitGroup{}
wg.Add(1)
source.runPeriodically(func() error {
source.runPeriodically(context.TODO(), func() error {
mu.Lock()
periods = append(periods, time.Since(lastCall))
mu.Unlock()
Expand Down
3 changes: 1 addition & 2 deletions wakuv2/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

package wakuv2

/* TODO-nwaku
import (
"context"
"crypto/ecdsa"
Expand Down Expand Up @@ -513,4 +512,4 @@ func (api *PublicWakuAPI) NewMessageFilter(req Criteria) (string, error) {
api.mu.Unlock()

return id, nil
} */
}
3 changes: 2 additions & 1 deletion wakuv2/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,5 @@ func TestMultipleTopicCopyInNewMessageFilter(t *testing.T) {
if !found {
t.Fatalf("Could not find filter with both topics")
}
} */
}
*/
6 changes: 3 additions & 3 deletions wakuv2/history_processor_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package wakuv2
import (
"github.com/libp2p/go-libp2p/core/peer"

"github.com/status-im/status-go/wakuv2/common"

"github.com/waku-org/go-waku/waku/v2/api/history"
"github.com/waku-org/go-waku/waku/v2/protocol"
)
Expand All @@ -16,9 +18,7 @@ func NewHistoryProcessorWrapper(waku *Waku) history.HistoryProcessor {
}

func (hr *HistoryProcessorWrapper) OnEnvelope(env *protocol.Envelope, processEnvelopes bool) error {
// TODO-nwaku
// return hr.waku.OnNewEnvelopes(env, common.StoreMessageType, processEnvelopes)
return nil
return hr.waku.OnNewEnvelopes(env, common.StoreMessageType, processEnvelopes)
}

func (hr *HistoryProcessorWrapper) OnRequestFailed(requestID []byte, peerID peer.ID, err error) {
Expand Down
44 changes: 14 additions & 30 deletions wakuv2/nwaku.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ import (
"github.com/golang/protobuf/proto"
"github.com/jellydator/ttlcache/v3"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/peerstore"
"github.com/multiformats/go-multiaddr"

"go.uber.org/zap"
Expand All @@ -300,6 +299,7 @@ import (
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/rpc"

"github.com/libp2p/go-libp2p/core/metrics"

Expand Down Expand Up @@ -342,7 +342,6 @@ const maxRelayPeers = 300
const randomPeersKeepAliveInterval = 5 * time.Second
const allPeersKeepAliveInterval = 5 * time.Minute

/* TODO-nwaku
type SentEnvelope struct {
Envelope *protocol.Envelope
PublishMethod publish.PublishMethod
Expand All @@ -364,7 +363,6 @@ type ITelemetryClient interface {
PushPeerCountByShard(ctx context.Context, peerCountByShard map[uint16]uint)
PushPeerCountByOrigin(ctx context.Context, peerCountByOrigin map[wps.Origin]uint)
}
*/

type WakuMessageHash = string
type WakuPubsubTopic = string
Expand Down Expand Up @@ -462,15 +460,14 @@ type Waku struct {
onHistoricMessagesRequestFailed func([]byte, peer.ID, error)
onPeerStats func(types.ConnStatus)

// statusTelemetryClient ITelemetryClient // TODO-nwaku
statusTelemetryClient ITelemetryClient

defaultShardInfo protocol.RelayShards
}

/* TODO-nwaku
func (w *Waku) SetStatusTelemetryClient(client ITelemetryClient) {
w.statusTelemetryClient = client
} */
}

func newTTLCache() *ttlcache.Cache[gethcommon.Hash, *common.ReceivedMessage] {
cache := ttlcache.New[gethcommon.Hash, *common.ReceivedMessage](ttlcache.WithTTL[gethcommon.Hash, *common.ReceivedMessage](cacheTTL))
Expand All @@ -497,12 +494,12 @@ func New(nodeKey *ecdsa.PrivateKey, fleet string, cfg *Config, nwakuCfg *WakuCon

defaultPubsubTopic, err := node.WakuDefaultPubsubTopic()
if err != nil {
fmt.Println("Error happened:", err.Error())
return nil, err
}

err = node.WakuRelaySubscribe(defaultPubsubTopic)
if err != nil {
fmt.Println("Error happened:", err.Error())
return nil, err
}

node.WakuSetEventCallback()
Expand Down Expand Up @@ -1003,6 +1000,7 @@ func (w *Waku) subscribeToPubsubTopicWithWakuRelay(topic string, pubkey *ecdsa.P
return nil
}
*/

// MaxMessageSize returns the maximum accepted message size.
func (w *Waku) MaxMessageSize() uint32 {
Expand All @@ -1024,7 +1022,7 @@ func (w *Waku) APIs() []rpc.API {
Public: false,
},
}
} */
}

// Protocols returns the waku sub-protocols ran by this particular client.
func (w *Waku) Protocols() []p2p.Protocol {
Expand Down Expand Up @@ -1277,7 +1275,6 @@ func (w *Waku) GetSymKey(id string) ([]byte, error) {
return nil, fmt.Errorf("non-existent key ID")
}

/* TODO-nwaku
// Subscribe installs a new message handler used for filtering, decrypting
// and subsequent storing of incoming messages.
func (w *Waku) Subscribe(f *common.Filter) (string, error) {
Expand Down Expand Up @@ -1332,13 +1329,12 @@ func (w *Waku) SkipPublishToTopic(value bool) {

func (w *Waku) ConfirmMessageDelivered(hashes []gethcommon.Hash) {
w.messageSender.MessagesDelivered(hashes)
} */
}

/* TODO-nwaku
// OnNewEnvelope is an interface from Waku FilterManager API that gets invoked when any new message is received by Filter.
func (w *Waku) OnNewEnvelope(env *protocol.Envelope) error {
return w.OnNewEnvelopes(env, common.RelayedMessageType, false)
} */
}

// Start implements node.Service, starting the background data propagation thread
// of the Waku protocol.
Expand Down Expand Up @@ -1614,20 +1610,18 @@ func (w *Waku) startMessageSender() error {
Event: common.EventEnvelopeSent,
})

// TODO-nwaku
/*if w.statusTelemetryClient != nil {
if w.statusTelemetryClient != nil {
w.statusTelemetryClient.PushMessageCheckSuccess(w.ctx, hash.Hex())
}*/
}
case hash := <-msgExpiredChan:
w.SendEnvelopeEvent(common.EnvelopeEvent{
Hash: hash,
Event: common.EventEnvelopeExpired,
})

// TODO-nwaku
/* if w.statusTelemetryClient != nil {
if w.statusTelemetryClient != nil {
w.statusTelemetryClient.PushMessageCheckFailure(w.ctx, hash.Hex())
}*/
}
}
}
}()
Expand Down Expand Up @@ -2203,12 +2197,6 @@ func (w *Waku) PeerID() peer.ID {
return ""
}

// TODO-nwaku
func (w *Waku) Peerstore() peerstore.Peerstore {
// return w.node.Host().Peerstore()
return nil
}

// validatePrivateKey checks the format of the given private key.
func validatePrivateKey(k *ecdsa.PrivateKey) bool {
if k == nil || k.D == nil || k.D.Sign() == 0 {
Expand Down Expand Up @@ -2539,7 +2527,7 @@ func (self *Waku) WakuRelaySubscribe(pubsubTopic string) error {
defer C.free(unsafe.Pointer(cPubsubTopic))

if self.wakuCtx == nil {
fmt.Println("ctx is nil")
return errors.New("wakuCtx is nil")
}
// if self.cPubsubTopic == nil {
// fmt.Println("cPubsubTopic is nil")
Expand Down Expand Up @@ -2688,8 +2676,6 @@ func (self *Waku) ListenAddresses() ([]multiaddr.Multiaddr, error) {
addrsRet = append(addrsRet, addr)
}

fmt.Println("AAAAAA listen addresses: ", listenAddresses)

return addrsRet, nil
}
errMsg := "error WakuListenAddresses: " +
Expand Down Expand Up @@ -2728,7 +2714,6 @@ func (self *Waku) ListPeersInMesh(pubsubTopic string) (int, error) {
numPeersStr := C.GoStringN(C.getMyCharPtr(resp), C.int(C.getMyCharLen(resp)))
numPeers, err := strconv.Atoi(numPeersStr)
if err != nil {
fmt.Println(":", err)
errMsg := "ListPeersInMesh - error converting string to int: " + err.Error()
return 0, errors.New(errMsg)
}
Expand Down Expand Up @@ -2758,7 +2743,6 @@ func (self *Waku) GetNumConnectedPeers(paramPubsubTopic ...string) (int, error)
numPeersStr := C.GoStringN(C.getMyCharPtr(resp), C.int(C.getMyCharLen(resp)))
numPeers, err := strconv.Atoi(numPeersStr)
if err != nil {
fmt.Println(":", err)
errMsg := "GetNumConnectedPeers - error converting string to int: " + err.Error()
return 0, errors.New(errMsg)
}
Expand Down

0 comments on commit ed5a9aa

Please sign in to comment.