chore_: uncomment code that would allow status-go/go-waku to compile and libwaku test to run (#5986)

This commit is contained in:
richΛrd 2024-10-24 10:35:01 -04:00 committed by Richard Ramos
parent 94bede0850
commit 94b702996e
No known key found for this signature in database
GPG Key ID: 1CE87DB518195760
6 changed files with 32 additions and 39 deletions

View File

@ -239,7 +239,11 @@ func (s *NTPTimeSource) Stop() {
} }
func (s *NTPTimeSource) GetCurrentTime() time.Time { 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() return s.Now()
} }
@ -249,7 +253,11 @@ func (s *NTPTimeSource) GetCurrentTimeInMillis() uint64 {
func GetCurrentTime() time.Time { func GetCurrentTime() time.Time {
ts := Default() ts := Default()
ts.Start(context.Background()) err := ts.Start(context.Background())
if err != nil {
panic("could not obtain timesource")
}
return ts.Now() return ts.Now()
} }

View File

@ -1,6 +1,7 @@
package timesource package timesource
import ( import (
"context"
"errors" "errors"
"sync" "sync"
"testing" "testing"
@ -214,7 +215,7 @@ func TestRunningPeriodically(t *testing.T) {
// on NTPTimeSource specified periods (fastNTPSyncPeriod & slowNTPSyncPeriod) // on NTPTimeSource specified periods (fastNTPSyncPeriod & slowNTPSyncPeriod)
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
wg.Add(1) wg.Add(1)
source.runPeriodically(func() error { source.runPeriodically(context.TODO(), func() error {
mu.Lock() mu.Lock()
periods = append(periods, time.Since(lastCall)) periods = append(periods, time.Since(lastCall))
mu.Unlock() mu.Unlock()

View File

@ -18,7 +18,6 @@
package wakuv2 package wakuv2
/* TODO-nwaku
import ( import (
"context" "context"
"crypto/ecdsa" "crypto/ecdsa"
@ -515,4 +514,4 @@ func (api *PublicWakuAPI) NewMessageFilter(req Criteria) (string, error) {
api.mu.Unlock() api.mu.Unlock()
return id, nil return id, nil
} */ }

View File

@ -68,4 +68,5 @@ func TestMultipleTopicCopyInNewMessageFilter(t *testing.T) {
if !found { if !found {
t.Fatalf("Could not find filter with both topics") t.Fatalf("Could not find filter with both topics")
} }
} */ }
*/

View File

@ -3,6 +3,8 @@ package wakuv2
import ( import (
"github.com/libp2p/go-libp2p/core/peer" "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/api/history"
"github.com/waku-org/go-waku/waku/v2/protocol" "github.com/waku-org/go-waku/waku/v2/protocol"
) )
@ -16,9 +18,7 @@ func NewHistoryProcessorWrapper(waku *Waku) history.HistoryProcessor {
} }
func (hr *HistoryProcessorWrapper) OnEnvelope(env *protocol.Envelope, processEnvelopes bool) error { func (hr *HistoryProcessorWrapper) OnEnvelope(env *protocol.Envelope, processEnvelopes bool) error {
// TODO-nwaku return hr.waku.OnNewEnvelopes(env, common.StoreMessageType, processEnvelopes)
// return hr.waku.OnNewEnvelopes(env, common.StoreMessageType, processEnvelopes)
return nil
} }
func (hr *HistoryProcessorWrapper) OnRequestFailed(requestID []byte, peerID peer.ID, err error) { func (hr *HistoryProcessorWrapper) OnRequestFailed(requestID []byte, peerID peer.ID, err error) {

View File

@ -286,7 +286,6 @@ import (
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"github.com/jellydator/ttlcache/v3" "github.com/jellydator/ttlcache/v3"
"github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/peerstore"
"github.com/multiformats/go-multiaddr" "github.com/multiformats/go-multiaddr"
"go.uber.org/zap" "go.uber.org/zap"
@ -300,6 +299,7 @@ import (
"github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/enode" "github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/rpc"
"github.com/libp2p/go-libp2p/core/metrics" "github.com/libp2p/go-libp2p/core/metrics"
@ -342,7 +342,6 @@ const maxRelayPeers = 300
const randomPeersKeepAliveInterval = 5 * time.Second const randomPeersKeepAliveInterval = 5 * time.Second
const allPeersKeepAliveInterval = 5 * time.Minute const allPeersKeepAliveInterval = 5 * time.Minute
/* TODO-nwaku
type SentEnvelope struct { type SentEnvelope struct {
Envelope *protocol.Envelope Envelope *protocol.Envelope
PublishMethod publish.PublishMethod PublishMethod publish.PublishMethod
@ -364,7 +363,6 @@ type ITelemetryClient interface {
PushPeerCountByShard(ctx context.Context, peerCountByShard map[uint16]uint) PushPeerCountByShard(ctx context.Context, peerCountByShard map[uint16]uint)
PushPeerCountByOrigin(ctx context.Context, peerCountByOrigin map[wps.Origin]uint) PushPeerCountByOrigin(ctx context.Context, peerCountByOrigin map[wps.Origin]uint)
} }
*/
type WakuMessageHash = string type WakuMessageHash = string
type WakuPubsubTopic = string type WakuPubsubTopic = string
@ -462,15 +460,14 @@ type Waku struct {
onHistoricMessagesRequestFailed func([]byte, peer.ID, error) onHistoricMessagesRequestFailed func([]byte, peer.ID, error)
onPeerStats func(types.ConnStatus) onPeerStats func(types.ConnStatus)
// statusTelemetryClient ITelemetryClient // TODO-nwaku statusTelemetryClient ITelemetryClient
defaultShardInfo protocol.RelayShards defaultShardInfo protocol.RelayShards
} }
/* TODO-nwaku
func (w *Waku) SetStatusTelemetryClient(client ITelemetryClient) { func (w *Waku) SetStatusTelemetryClient(client ITelemetryClient) {
w.statusTelemetryClient = client w.statusTelemetryClient = client
} */ }
func newTTLCache() *ttlcache.Cache[gethcommon.Hash, *common.ReceivedMessage] { func newTTLCache() *ttlcache.Cache[gethcommon.Hash, *common.ReceivedMessage] {
cache := ttlcache.New[gethcommon.Hash, *common.ReceivedMessage](ttlcache.WithTTL[gethcommon.Hash, *common.ReceivedMessage](cacheTTL)) cache := ttlcache.New[gethcommon.Hash, *common.ReceivedMessage](ttlcache.WithTTL[gethcommon.Hash, *common.ReceivedMessage](cacheTTL))
@ -497,12 +494,12 @@ func New(nodeKey *ecdsa.PrivateKey, fleet string, cfg *Config, nwakuCfg *WakuCon
defaultPubsubTopic, err := node.WakuDefaultPubsubTopic() defaultPubsubTopic, err := node.WakuDefaultPubsubTopic()
if err != nil { if err != nil {
fmt.Println("Error happened:", err.Error()) return nil, err
} }
err = node.WakuRelaySubscribe(defaultPubsubTopic) err = node.WakuRelaySubscribe(defaultPubsubTopic)
if err != nil { if err != nil {
fmt.Println("Error happened:", err.Error()) return nil, err
} }
node.WakuSetEventCallback() node.WakuSetEventCallback()
@ -1003,6 +1000,7 @@ func (w *Waku) subscribeToPubsubTopicWithWakuRelay(topic string, pubkey *ecdsa.P
return nil return nil
} }
*/
// MaxMessageSize returns the maximum accepted message size. // MaxMessageSize returns the maximum accepted message size.
func (w *Waku) MaxMessageSize() uint32 { func (w *Waku) MaxMessageSize() uint32 {
@ -1024,7 +1022,7 @@ func (w *Waku) APIs() []rpc.API {
Public: false, Public: false,
}, },
} }
} */ }
// Protocols returns the waku sub-protocols ran by this particular client. // Protocols returns the waku sub-protocols ran by this particular client.
func (w *Waku) Protocols() []p2p.Protocol { func (w *Waku) Protocols() []p2p.Protocol {
@ -1277,7 +1275,6 @@ func (w *Waku) GetSymKey(id string) ([]byte, error) {
return nil, fmt.Errorf("non-existent key ID") return nil, fmt.Errorf("non-existent key ID")
} }
/* TODO-nwaku
// Subscribe installs a new message handler used for filtering, decrypting // Subscribe installs a new message handler used for filtering, decrypting
// and subsequent storing of incoming messages. // and subsequent storing of incoming messages.
func (w *Waku) Subscribe(f *common.Filter) (string, error) { func (w *Waku) Subscribe(f *common.Filter) (string, error) {
@ -1332,13 +1329,12 @@ func (w *Waku) SkipPublishToTopic(value bool) {
func (w *Waku) ConfirmMessageDelivered(hashes []gethcommon.Hash) { func (w *Waku) ConfirmMessageDelivered(hashes []gethcommon.Hash) {
w.messageSender.MessagesDelivered(hashes) 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. // 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 { func (w *Waku) OnNewEnvelope(env *protocol.Envelope) error {
return w.OnNewEnvelopes(env, common.RelayedMessageType, false) return w.OnNewEnvelopes(env, common.RelayedMessageType, false)
} */ }
// Start implements node.Service, starting the background data propagation thread // Start implements node.Service, starting the background data propagation thread
// of the Waku protocol. // of the Waku protocol.
@ -1614,20 +1610,18 @@ func (w *Waku) startMessageSender() error {
Event: common.EventEnvelopeSent, Event: common.EventEnvelopeSent,
}) })
// TODO-nwaku if w.statusTelemetryClient != nil {
/*if w.statusTelemetryClient != nil {
w.statusTelemetryClient.PushMessageCheckSuccess(w.ctx, hash.Hex()) w.statusTelemetryClient.PushMessageCheckSuccess(w.ctx, hash.Hex())
}*/ }
case hash := <-msgExpiredChan: case hash := <-msgExpiredChan:
w.SendEnvelopeEvent(common.EnvelopeEvent{ w.SendEnvelopeEvent(common.EnvelopeEvent{
Hash: hash, Hash: hash,
Event: common.EventEnvelopeExpired, Event: common.EventEnvelopeExpired,
}) })
// TODO-nwaku if w.statusTelemetryClient != nil {
/* if w.statusTelemetryClient != nil {
w.statusTelemetryClient.PushMessageCheckFailure(w.ctx, hash.Hex()) w.statusTelemetryClient.PushMessageCheckFailure(w.ctx, hash.Hex())
}*/ }
} }
} }
}() }()
@ -2203,12 +2197,6 @@ func (w *Waku) PeerID() peer.ID {
return "" 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. // validatePrivateKey checks the format of the given private key.
func validatePrivateKey(k *ecdsa.PrivateKey) bool { func validatePrivateKey(k *ecdsa.PrivateKey) bool {
if k == nil || k.D == nil || k.D.Sign() == 0 { if k == nil || k.D == nil || k.D.Sign() == 0 {
@ -2539,7 +2527,7 @@ func (self *Waku) WakuRelaySubscribe(pubsubTopic string) error {
defer C.free(unsafe.Pointer(cPubsubTopic)) defer C.free(unsafe.Pointer(cPubsubTopic))
if self.wakuCtx == nil { if self.wakuCtx == nil {
fmt.Println("ctx is nil") return errors.New("wakuCtx is nil")
} }
// if self.cPubsubTopic == nil { // if self.cPubsubTopic == nil {
// fmt.Println("cPubsubTopic is nil") // fmt.Println("cPubsubTopic is nil")
@ -2688,8 +2676,6 @@ func (self *Waku) ListenAddresses() ([]multiaddr.Multiaddr, error) {
addrsRet = append(addrsRet, addr) addrsRet = append(addrsRet, addr)
} }
fmt.Println("AAAAAA listen addresses: ", listenAddresses)
return addrsRet, nil return addrsRet, nil
} }
errMsg := "error WakuListenAddresses: " + errMsg := "error WakuListenAddresses: " +
@ -2728,7 +2714,6 @@ func (self *Waku) ListPeersInMesh(pubsubTopic string) (int, error) {
numPeersStr := C.GoStringN(C.getMyCharPtr(resp), C.int(C.getMyCharLen(resp))) numPeersStr := C.GoStringN(C.getMyCharPtr(resp), C.int(C.getMyCharLen(resp)))
numPeers, err := strconv.Atoi(numPeersStr) numPeers, err := strconv.Atoi(numPeersStr)
if err != nil { if err != nil {
fmt.Println(":", err)
errMsg := "ListPeersInMesh - error converting string to int: " + err.Error() errMsg := "ListPeersInMesh - error converting string to int: " + err.Error()
return 0, errors.New(errMsg) return 0, errors.New(errMsg)
} }
@ -2758,7 +2743,6 @@ func (self *Waku) GetNumConnectedPeers(paramPubsubTopic ...string) (int, error)
numPeersStr := C.GoStringN(C.getMyCharPtr(resp), C.int(C.getMyCharLen(resp))) numPeersStr := C.GoStringN(C.getMyCharPtr(resp), C.int(C.getMyCharLen(resp)))
numPeers, err := strconv.Atoi(numPeersStr) numPeers, err := strconv.Atoi(numPeersStr)
if err != nil { if err != nil {
fmt.Println(":", err)
errMsg := "GetNumConnectedPeers - error converting string to int: " + err.Error() errMsg := "GetNumConnectedPeers - error converting string to int: " + err.Error()
return 0, errors.New(errMsg) return 0, errors.New(errMsg)
} }