From 7c56ceb1396c0d2b5b6984a80d989ce16f89e50c Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Wed, 29 Mar 2023 11:35:07 -0400 Subject: [PATCH] chore: remove swap protocol --- waku/v2/node/wakunode2.go | 11 +- waku/v2/node/wakuoptions.go | 16 -- waku/v2/node/wakuoptions_test.go | 2 +- waku/v2/protocol/store/waku_resume_test.go | 14 +- waku/v2/protocol/store/waku_store_common.go | 4 +- .../store/waku_store_persistence_test.go | 2 +- .../store/waku_store_protocol_test.go | 18 +- .../protocol/store/waku_store_query_test.go | 16 +- waku/v2/protocol/swap/pb/generate.go | 3 - waku/v2/protocol/swap/pb/waku_swap.pb.go | 243 ------------------ waku/v2/protocol/swap/pb/waku_swap.proto | 15 -- waku/v2/protocol/swap/waku_swap.go | 87 ------- waku/v2/protocol/swap/waku_swap_option.go | 29 --- .../v2/protocol/swap/waku_swap_option_test.go | 24 -- waku/v2/protocol/swap/waku_swap_test.go | 21 -- 15 files changed, 28 insertions(+), 477 deletions(-) delete mode 100644 waku/v2/protocol/swap/pb/generate.go delete mode 100644 waku/v2/protocol/swap/pb/waku_swap.pb.go delete mode 100644 waku/v2/protocol/swap/pb/waku_swap.proto delete mode 100644 waku/v2/protocol/swap/waku_swap.go delete mode 100644 waku/v2/protocol/swap/waku_swap_option.go delete mode 100644 waku/v2/protocol/swap/waku_swap_option_test.go delete mode 100644 waku/v2/protocol/swap/waku_swap_test.go diff --git a/waku/v2/node/wakunode2.go b/waku/v2/node/wakunode2.go index b5a3dc20..8292a413 100644 --- a/waku/v2/node/wakunode2.go +++ b/waku/v2/node/wakunode2.go @@ -40,7 +40,6 @@ import ( "github.com/waku-org/go-waku/waku/v2/protocol/peer_exchange" "github.com/waku-org/go-waku/waku/v2/protocol/relay" "github.com/waku-org/go-waku/waku/v2/protocol/store" - "github.com/waku-org/go-waku/waku/v2/protocol/swap" "github.com/waku-org/go-waku/waku/v2/rendezvous" "github.com/waku-org/go-waku/waku/v2/timesource" @@ -77,7 +76,6 @@ type WakuNode struct { relay Service lightPush Service - swap Service peerConnector PeerConnectorService discoveryV5 Service peerExchange Service @@ -114,7 +112,7 @@ type WakuNode struct { } func defaultStoreFactory(w *WakuNode) store.Store { - return store.NewWakuStore(w.host, w.swap, w.opts.messageProvider, w.timesource, w.log) + return store.NewWakuStore(w.host, w.opts.messageProvider, w.timesource, w.log) } // New is used to instantiate a WakuNode using a set of WakuNodeOptions @@ -230,13 +228,6 @@ func New(opts ...WakuNodeOption) (*WakuNode, error) { w.filterV2Light = filterv2.NewWakuFilterLightnode(w.host, w.bcaster, w.timesource, w.log) w.lightPush = lightpush.NewWakuLightPush(w.host, w.Relay(), w.log) - if w.opts.enableSwap { - w.swap = swap.NewWakuSwap(w.log, []swap.SwapOption{ - swap.WithMode(w.opts.swapMode), - swap.WithThreshold(w.opts.swapPaymentThreshold, w.opts.swapDisconnectThreshold), - }...) - } - if params.storeFactory != nil { w.storeFactory = params.storeFactory } else { diff --git a/waku/v2/node/wakuoptions.go b/waku/v2/node/wakuoptions.go index e615b608..9f42ce3d 100644 --- a/waku/v2/node/wakuoptions.go +++ b/waku/v2/node/wakuoptions.go @@ -76,7 +76,6 @@ type WakuNodeParameters struct { minRelayPeersToPublish int enableStore bool - enableSwap bool resumeNodes []multiaddr.Multiaddr messageProvider store.MessageProvider @@ -86,10 +85,6 @@ type WakuNodeParameters struct { enableRendezvousServer bool rendezvousDB *rendezvous.DB - swapMode int - swapDisconnectThreshold int - swapPaymentThreshold int - discoveryMinPeers int enableDiscV5 bool @@ -373,17 +368,6 @@ func WithWakuStoreFactory(factory storeFactory) WakuNodeOption { } } -// WithWakuSwap set the option of the Waku V2 Swap protocol -func WithWakuSwap(mode int, disconnectThreshold, paymentThreshold int) WakuNodeOption { - return func(params *WakuNodeParameters) error { - params.enableSwap = true - params.swapMode = mode - params.swapDisconnectThreshold = disconnectThreshold - params.swapPaymentThreshold = paymentThreshold - return nil - } -} - // WithMessageProvider is a WakuNodeOption that sets the MessageProvider // used to store and retrieve persisted messages func WithMessageProvider(s store.MessageProvider) WakuNodeOption { diff --git a/waku/v2/node/wakuoptions_test.go b/waku/v2/node/wakuoptions_test.go index f0f70bd7..5ece6a04 100644 --- a/waku/v2/node/wakuoptions_test.go +++ b/waku/v2/node/wakuoptions_test.go @@ -28,7 +28,7 @@ func TestWakuOptions(t *testing.T) { require.NoError(t, err) storeFactory := func(w *WakuNode) store.Store { - return store.NewWakuStore(w.host, w.swap, w.opts.messageProvider, w.timesource, w.log) + return store.NewWakuStore(w.host, w.opts.messageProvider, w.timesource, w.log) } options := []WakuNodeOption{ diff --git a/waku/v2/protocol/store/waku_resume_test.go b/waku/v2/protocol/store/waku_resume_test.go index bb407682..706355fa 100644 --- a/waku/v2/protocol/store/waku_resume_test.go +++ b/waku/v2/protocol/store/waku_resume_test.go @@ -22,7 +22,7 @@ func TestFindLastSeenMessage(t *testing.T) { msg4 := protocol.NewEnvelope(tests.CreateWakuMessage("4", 4), utils.GetUnixEpoch(), "test") msg5 := protocol.NewEnvelope(tests.CreateWakuMessage("5", 5), utils.GetUnixEpoch(), "test") - s := NewWakuStore(nil, nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) + s := NewWakuStore(nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) _ = s.storeMessage(msg1) _ = s.storeMessage(msg3) _ = s.storeMessage(msg5) @@ -42,7 +42,7 @@ func TestResume(t *testing.T) { host1, err := libp2p.New(libp2p.DefaultTransports, libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0")) require.NoError(t, err) - s1 := NewWakuStore(host1, nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) + s1 := NewWakuStore(host1, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) err = s1.Start(ctx) require.NoError(t, err) @@ -62,7 +62,7 @@ func TestResume(t *testing.T) { host2, err := libp2p.New(libp2p.DefaultTransports, libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0")) require.NoError(t, err) - s2 := NewWakuStore(host2, nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) + s2 := NewWakuStore(host2, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) err = s2.Start(ctx) require.NoError(t, err) defer s2.Stop() @@ -99,7 +99,7 @@ func TestResumeWithListOfPeers(t *testing.T) { host1, err := libp2p.New(libp2p.DefaultTransports, libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0")) require.NoError(t, err) - s1 := NewWakuStore(host1, nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) + s1 := NewWakuStore(host1, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) err = s1.Start(ctx) require.NoError(t, err) @@ -112,7 +112,7 @@ func TestResumeWithListOfPeers(t *testing.T) { host2, err := libp2p.New(libp2p.DefaultTransports, libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0")) require.NoError(t, err) - s2 := NewWakuStore(host2, nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) + s2 := NewWakuStore(host2, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) err = s2.Start(ctx) require.NoError(t, err) defer s2.Stop() @@ -138,7 +138,7 @@ func TestResumeWithoutSpecifyingPeer(t *testing.T) { host1, err := libp2p.New(libp2p.DefaultTransports, libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0")) require.NoError(t, err) - s1 := NewWakuStore(host1, nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) + s1 := NewWakuStore(host1, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) err = s1.Start(ctx) require.NoError(t, err) @@ -151,7 +151,7 @@ func TestResumeWithoutSpecifyingPeer(t *testing.T) { host2, err := libp2p.New(libp2p.DefaultTransports, libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0")) require.NoError(t, err) - s2 := NewWakuStore(host2, nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) + s2 := NewWakuStore(host2, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) err = s2.Start(ctx) require.NoError(t, err) diff --git a/waku/v2/protocol/store/waku_store_common.go b/waku/v2/protocol/store/waku_store_common.go index 565f3f28..9ea77e57 100644 --- a/waku/v2/protocol/store/waku_store_common.go +++ b/waku/v2/protocol/store/waku_store_common.go @@ -60,15 +60,13 @@ type WakuStore struct { msgProvider MessageProvider h host.Host - swap WakuSwap } // NewWakuStore creates a WakuStore using an specific MessageProvider for storing the messages -func NewWakuStore(host host.Host, swap WakuSwap, p MessageProvider, timesource timesource.Timesource, log *zap.Logger) *WakuStore { +func NewWakuStore(host host.Host, p MessageProvider, timesource timesource.Timesource, log *zap.Logger) *WakuStore { wakuStore := new(WakuStore) wakuStore.msgProvider = p wakuStore.h = host - wakuStore.swap = swap wakuStore.wg = &sync.WaitGroup{} wakuStore.log = log.Named("store") wakuStore.timesource = timesource diff --git a/waku/v2/protocol/store/waku_store_persistence_test.go b/waku/v2/protocol/store/waku_store_persistence_test.go index 9fcb5eeb..d49cae3d 100644 --- a/waku/v2/protocol/store/waku_store_persistence_test.go +++ b/waku/v2/protocol/store/waku_store_persistence_test.go @@ -14,7 +14,7 @@ import ( func TestStorePersistence(t *testing.T) { db := MemoryDB(t) - s1 := NewWakuStore(nil, nil, db, timesource.NewDefaultClock(), utils.Logger()) + s1 := NewWakuStore(nil, db, timesource.NewDefaultClock(), utils.Logger()) defaultPubSubTopic := "test" defaultContentTopic := "1" diff --git a/waku/v2/protocol/store/waku_store_protocol_test.go b/waku/v2/protocol/store/waku_store_protocol_test.go index deabaaa4..c242e94c 100644 --- a/waku/v2/protocol/store/waku_store_protocol_test.go +++ b/waku/v2/protocol/store/waku_store_protocol_test.go @@ -22,7 +22,7 @@ func TestWakuStoreProtocolQuery(t *testing.T) { host1, err := libp2p.New(libp2p.DefaultTransports, libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0")) require.NoError(t, err) - s1 := NewWakuStore(host1, nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) + s1 := NewWakuStore(host1, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) err = s1.Start(ctx) require.NoError(t, err) @@ -43,7 +43,7 @@ func TestWakuStoreProtocolQuery(t *testing.T) { // Simulate a message has been received via relay protocol s1.MsgC <- protocol.NewEnvelope(msg, utils.GetUnixEpoch(), pubsubTopic1) - s2 := NewWakuStore(host2, nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) + s2 := NewWakuStore(host2, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) err = s2.Start(ctx) require.NoError(t, err) defer s2.Stop() @@ -71,7 +71,7 @@ func TestWakuStoreProtocolLocalQuery(t *testing.T) { host1, err := libp2p.New(libp2p.DefaultTransports, libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0")) require.NoError(t, err) - s1 := NewWakuStore(host1, nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) + s1 := NewWakuStore(host1, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) err = s1.Start(ctx) require.NoError(t, err) @@ -111,7 +111,7 @@ func TestWakuStoreProtocolNext(t *testing.T) { require.NoError(t, err) db := MemoryDB(t) - s1 := NewWakuStore(host1, nil, db, timesource.NewDefaultClock(), utils.Logger()) + s1 := NewWakuStore(host1, db, timesource.NewDefaultClock(), utils.Logger()) err = s1.Start(ctx) require.NoError(t, err) @@ -137,7 +137,7 @@ func TestWakuStoreProtocolNext(t *testing.T) { err = host2.Peerstore().AddProtocols(host1.ID(), StoreID_v20beta4) require.NoError(t, err) - s2 := NewWakuStore(host2, nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) + s2 := NewWakuStore(host2, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) err = s2.Start(ctx) require.NoError(t, err) defer s2.Stop() @@ -181,7 +181,7 @@ func TestWakuStoreResult(t *testing.T) { require.NoError(t, err) db := MemoryDB(t) - s1 := NewWakuStore(host1, nil, db, timesource.NewDefaultClock(), utils.Logger()) + s1 := NewWakuStore(host1, db, timesource.NewDefaultClock(), utils.Logger()) err = s1.Start(ctx) require.NoError(t, err) @@ -207,7 +207,7 @@ func TestWakuStoreResult(t *testing.T) { err = host2.Peerstore().AddProtocols(host1.ID(), StoreID_v20beta4) require.NoError(t, err) - s2 := NewWakuStore(host2, nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) + s2 := NewWakuStore(host2, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) err = s2.Start(ctx) require.NoError(t, err) defer s2.Stop() @@ -266,7 +266,7 @@ func TestWakuStoreProtocolFind(t *testing.T) { host1, err := libp2p.New(libp2p.DefaultTransports, libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0")) require.NoError(t, err) - s1 := NewWakuStore(host1, nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) + s1 := NewWakuStore(host1, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) err = s1.Start(ctx) require.NoError(t, err) defer s1.Stop() @@ -301,7 +301,7 @@ func TestWakuStoreProtocolFind(t *testing.T) { err = host2.Peerstore().AddProtocols(host1.ID(), StoreID_v20beta4) require.NoError(t, err) - s2 := NewWakuStore(host2, nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) + s2 := NewWakuStore(host2, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) err = s2.Start(ctx) require.NoError(t, err) defer s2.Stop() diff --git a/waku/v2/protocol/store/waku_store_query_test.go b/waku/v2/protocol/store/waku_store_query_test.go index 4342f2ab..f95a4ffa 100644 --- a/waku/v2/protocol/store/waku_store_query_test.go +++ b/waku/v2/protocol/store/waku_store_query_test.go @@ -21,7 +21,7 @@ func TestStoreQuery(t *testing.T) { msg1 := tests.CreateWakuMessage(defaultContentTopic, utils.GetUnixEpoch()) msg2 := tests.CreateWakuMessage("2", utils.GetUnixEpoch()) - s := NewWakuStore(nil, nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) + s := NewWakuStore(nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) _ = s.storeMessage(protocol.NewEnvelope(msg1, utils.GetUnixEpoch(), defaultPubSubTopic)) _ = s.storeMessage(protocol.NewEnvelope(msg2, utils.GetUnixEpoch(), defaultPubSubTopic)) @@ -47,7 +47,7 @@ func TestStoreQueryMultipleContentFilters(t *testing.T) { msg2 := tests.CreateWakuMessage(topic2, utils.GetUnixEpoch()) msg3 := tests.CreateWakuMessage(topic3, utils.GetUnixEpoch()) - s := NewWakuStore(nil, nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) + s := NewWakuStore(nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) _ = s.storeMessage(protocol.NewEnvelope(msg1, utils.GetUnixEpoch(), defaultPubSubTopic)) _ = s.storeMessage(protocol.NewEnvelope(msg2, utils.GetUnixEpoch(), defaultPubSubTopic)) @@ -80,7 +80,7 @@ func TestStoreQueryPubsubTopicFilter(t *testing.T) { msg2 := tests.CreateWakuMessage(topic2, utils.GetUnixEpoch()) msg3 := tests.CreateWakuMessage(topic3, utils.GetUnixEpoch()) - s := NewWakuStore(nil, nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) + s := NewWakuStore(nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) _ = s.storeMessage(protocol.NewEnvelope(msg1, utils.GetUnixEpoch(), pubsubTopic1)) _ = s.storeMessage(protocol.NewEnvelope(msg2, utils.GetUnixEpoch(), pubsubTopic2)) _ = s.storeMessage(protocol.NewEnvelope(msg3, utils.GetUnixEpoch(), pubsubTopic2)) @@ -112,7 +112,7 @@ func TestStoreQueryPubsubTopicNoMatch(t *testing.T) { msg2 := tests.CreateWakuMessage(topic2, utils.GetUnixEpoch()) msg3 := tests.CreateWakuMessage(topic3, utils.GetUnixEpoch()) - s := NewWakuStore(nil, nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) + s := NewWakuStore(nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) _ = s.storeMessage(protocol.NewEnvelope(msg1, utils.GetUnixEpoch(), pubsubTopic2)) _ = s.storeMessage(protocol.NewEnvelope(msg2, utils.GetUnixEpoch(), pubsubTopic2)) _ = s.storeMessage(protocol.NewEnvelope(msg3, utils.GetUnixEpoch(), pubsubTopic2)) @@ -134,7 +134,7 @@ func TestStoreQueryPubsubTopicAllMessages(t *testing.T) { msg2 := tests.CreateWakuMessage(topic2, utils.GetUnixEpoch()) msg3 := tests.CreateWakuMessage(topic3, utils.GetUnixEpoch()) - s := NewWakuStore(nil, nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) + s := NewWakuStore(nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) _ = s.storeMessage(protocol.NewEnvelope(msg1, utils.GetUnixEpoch(), pubsubTopic1)) _ = s.storeMessage(protocol.NewEnvelope(msg2, utils.GetUnixEpoch(), pubsubTopic1)) _ = s.storeMessage(protocol.NewEnvelope(msg3, utils.GetUnixEpoch(), pubsubTopic1)) @@ -153,7 +153,7 @@ func TestStoreQueryForwardPagination(t *testing.T) { topic1 := "1" pubsubTopic1 := "topic1" - s := NewWakuStore(nil, nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) + s := NewWakuStore(nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) for i := 0; i < 10; i++ { msg := tests.CreateWakuMessage(topic1, utils.GetUnixEpoch()) msg.Payload = []byte{byte(i)} @@ -177,7 +177,7 @@ func TestStoreQueryBackwardPagination(t *testing.T) { topic1 := "1" pubsubTopic1 := "topic1" - s := NewWakuStore(nil, nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) + s := NewWakuStore(nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) for i := 0; i < 10; i++ { msg := &wpb.WakuMessage{ Payload: []byte{byte(i)}, @@ -203,7 +203,7 @@ func TestStoreQueryBackwardPagination(t *testing.T) { } func TestTemporalHistoryQueries(t *testing.T) { - s := NewWakuStore(nil, nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) + s := NewWakuStore(nil, MemoryDB(t), timesource.NewDefaultClock(), utils.Logger()) var messages []*wpb.WakuMessage for i := 0; i < 10; i++ { diff --git a/waku/v2/protocol/swap/pb/generate.go b/waku/v2/protocol/swap/pb/generate.go deleted file mode 100644 index 2b517b2c..00000000 --- a/waku/v2/protocol/swap/pb/generate.go +++ /dev/null @@ -1,3 +0,0 @@ -package pb - -//go:generate protoc -I. --go_opt=paths=source_relative --go_opt=Mwaku_swap.proto=github.com/waku-org/go-waku/waku/v2/protocol/swap/pb --go_out=. ./waku_swap.proto diff --git a/waku/v2/protocol/swap/pb/waku_swap.pb.go b/waku/v2/protocol/swap/pb/waku_swap.pb.go deleted file mode 100644 index c7509906..00000000 --- a/waku/v2/protocol/swap/pb/waku_swap.pb.go +++ /dev/null @@ -1,243 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.26.0 -// protoc v3.21.12 -// source: waku_swap.proto - -package pb - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type Cheque struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - IssuerAddress string `protobuf:"bytes,1,opt,name=issuerAddress,proto3" json:"issuerAddress,omitempty"` - Beneficiary []byte `protobuf:"bytes,2,opt,name=beneficiary,proto3" json:"beneficiary,omitempty"` - Date uint32 `protobuf:"varint,3,opt,name=date,proto3" json:"date,omitempty"` - Amount uint32 `protobuf:"varint,4,opt,name=amount,proto3" json:"amount,omitempty"` - Signature []byte `protobuf:"bytes,5,opt,name=signature,proto3" json:"signature,omitempty"` -} - -func (x *Cheque) Reset() { - *x = Cheque{} - if protoimpl.UnsafeEnabled { - mi := &file_waku_swap_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Cheque) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Cheque) ProtoMessage() {} - -func (x *Cheque) ProtoReflect() protoreflect.Message { - mi := &file_waku_swap_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Cheque.ProtoReflect.Descriptor instead. -func (*Cheque) Descriptor() ([]byte, []int) { - return file_waku_swap_proto_rawDescGZIP(), []int{0} -} - -func (x *Cheque) GetIssuerAddress() string { - if x != nil { - return x.IssuerAddress - } - return "" -} - -func (x *Cheque) GetBeneficiary() []byte { - if x != nil { - return x.Beneficiary - } - return nil -} - -func (x *Cheque) GetDate() uint32 { - if x != nil { - return x.Date - } - return 0 -} - -func (x *Cheque) GetAmount() uint32 { - if x != nil { - return x.Amount - } - return 0 -} - -func (x *Cheque) GetSignature() []byte { - if x != nil { - return x.Signature - } - return nil -} - -type Handshake struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Beneficiary []byte `protobuf:"bytes,1,opt,name=beneficiary,proto3" json:"beneficiary,omitempty"` -} - -func (x *Handshake) Reset() { - *x = Handshake{} - if protoimpl.UnsafeEnabled { - mi := &file_waku_swap_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Handshake) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Handshake) ProtoMessage() {} - -func (x *Handshake) ProtoReflect() protoreflect.Message { - mi := &file_waku_swap_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Handshake.ProtoReflect.Descriptor instead. -func (*Handshake) Descriptor() ([]byte, []int) { - return file_waku_swap_proto_rawDescGZIP(), []int{1} -} - -func (x *Handshake) GetBeneficiary() []byte { - if x != nil { - return x.Beneficiary - } - return nil -} - -var File_waku_swap_proto protoreflect.FileDescriptor - -var file_waku_swap_proto_rawDesc = []byte{ - 0x0a, 0x0f, 0x77, 0x61, 0x6b, 0x75, 0x5f, 0x73, 0x77, 0x61, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x12, 0x02, 0x70, 0x62, 0x22, 0x9a, 0x01, 0x0a, 0x06, 0x43, 0x68, 0x65, 0x71, 0x75, 0x65, - 0x12, 0x24, 0x0a, 0x0d, 0x69, 0x73, 0x73, 0x75, 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, - 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x69, 0x73, 0x73, 0x75, 0x65, 0x72, 0x41, - 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x20, 0x0a, 0x0b, 0x62, 0x65, 0x6e, 0x65, 0x66, 0x69, - 0x63, 0x69, 0x61, 0x72, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x62, 0x65, 0x6e, - 0x65, 0x66, 0x69, 0x63, 0x69, 0x61, 0x72, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x65, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x64, 0x61, 0x74, 0x65, 0x12, 0x16, 0x0a, 0x06, - 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x61, 0x6d, - 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, - 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, - 0x72, 0x65, 0x22, 0x2d, 0x0a, 0x09, 0x48, 0x61, 0x6e, 0x64, 0x73, 0x68, 0x61, 0x6b, 0x65, 0x12, - 0x20, 0x0a, 0x0b, 0x62, 0x65, 0x6e, 0x65, 0x66, 0x69, 0x63, 0x69, 0x61, 0x72, 0x79, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x62, 0x65, 0x6e, 0x65, 0x66, 0x69, 0x63, 0x69, 0x61, 0x72, - 0x79, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_waku_swap_proto_rawDescOnce sync.Once - file_waku_swap_proto_rawDescData = file_waku_swap_proto_rawDesc -) - -func file_waku_swap_proto_rawDescGZIP() []byte { - file_waku_swap_proto_rawDescOnce.Do(func() { - file_waku_swap_proto_rawDescData = protoimpl.X.CompressGZIP(file_waku_swap_proto_rawDescData) - }) - return file_waku_swap_proto_rawDescData -} - -var file_waku_swap_proto_msgTypes = make([]protoimpl.MessageInfo, 2) -var file_waku_swap_proto_goTypes = []interface{}{ - (*Cheque)(nil), // 0: pb.Cheque - (*Handshake)(nil), // 1: pb.Handshake -} -var file_waku_swap_proto_depIdxs = []int32{ - 0, // [0:0] is the sub-list for method output_type - 0, // [0:0] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name -} - -func init() { file_waku_swap_proto_init() } -func file_waku_swap_proto_init() { - if File_waku_swap_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_waku_swap_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Cheque); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_waku_swap_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Handshake); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_waku_swap_proto_rawDesc, - NumEnums: 0, - NumMessages: 2, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_waku_swap_proto_goTypes, - DependencyIndexes: file_waku_swap_proto_depIdxs, - MessageInfos: file_waku_swap_proto_msgTypes, - }.Build() - File_waku_swap_proto = out.File - file_waku_swap_proto_rawDesc = nil - file_waku_swap_proto_goTypes = nil - file_waku_swap_proto_depIdxs = nil -} diff --git a/waku/v2/protocol/swap/pb/waku_swap.proto b/waku/v2/protocol/swap/pb/waku_swap.proto deleted file mode 100644 index 37f3344a..00000000 --- a/waku/v2/protocol/swap/pb/waku_swap.proto +++ /dev/null @@ -1,15 +0,0 @@ -syntax = "proto3"; - -package pb; - -message Cheque { - string issuerAddress = 1; - bytes beneficiary = 2; - uint32 date = 3; - uint32 amount = 4; - bytes signature = 5; -} - -message Handshake { - bytes beneficiary = 1; -} \ No newline at end of file diff --git a/waku/v2/protocol/swap/waku_swap.go b/waku/v2/protocol/swap/waku_swap.go deleted file mode 100644 index 81733dea..00000000 --- a/waku/v2/protocol/swap/waku_swap.go +++ /dev/null @@ -1,87 +0,0 @@ -package swap - -import ( - "context" - "sync" - - "github.com/libp2p/go-libp2p/core/protocol" - "go.uber.org/zap" -) - -const ( - SoftMode int = 0 - MockMode int = 1 - HardMode int = 2 -) - -const WakuSwapID_v200 = protocol.ID("/vac/waku/swap/2.0.0-beta1") - -type WakuSwap struct { - params *SwapParameters - - log *zap.Logger - - Accounting map[string]int - accountingMutex sync.RWMutex -} - -func NewWakuSwap(log *zap.Logger, opts ...SwapOption) *WakuSwap { - params := &SwapParameters{} - - optList := DefaultOptions() - optList = append(optList, opts...) - for _, opt := range optList { - opt(params) - } - - return &WakuSwap{ - params: params, - log: log.Named("swap"), - Accounting: make(map[string]int), - } -} - -func (s *WakuSwap) sendCheque(peerId string) { - s.log.Debug("not yet implemented") -} - -func (s *WakuSwap) applyPolicy(peerId string) { - logger := s.log.With(zap.String("peer", peerId)) - if s.Accounting[peerId] <= s.params.disconnectThreshold { - logger.Warn("disconnect threshold reached", zap.Int("value", s.Accounting[peerId])) - } - - if s.Accounting[peerId] >= s.params.paymentThreshold { - logger.Warn("payment threshold reached", zap.Int("value", s.Accounting[peerId])) - if s.params.mode != HardMode { - s.sendCheque(peerId) - } - } -} - -func (s *WakuSwap) Credit(peerId string, n int) { - s.accountingMutex.Lock() - defer s.accountingMutex.Unlock() - - s.Accounting[peerId] -= n - s.applyPolicy(peerId) -} - -func (s *WakuSwap) Debit(peerId string, n int) { - s.accountingMutex.Lock() - defer s.accountingMutex.Unlock() - - s.Accounting[peerId] += n - s.applyPolicy(peerId) -} - -func (s *WakuSwap) Start(ctx context.Context) error { - return nil -} - -func (s *WakuSwap) Stop() { -} - -func (s *WakuSwap) IsStarted() bool { - return false -} diff --git a/waku/v2/protocol/swap/waku_swap_option.go b/waku/v2/protocol/swap/waku_swap_option.go deleted file mode 100644 index d73a0047..00000000 --- a/waku/v2/protocol/swap/waku_swap_option.go +++ /dev/null @@ -1,29 +0,0 @@ -package swap - -type SwapParameters struct { - mode int - paymentThreshold int - disconnectThreshold int -} - -type SwapOption func(*SwapParameters) - -func WithMode(mode int) SwapOption { - return func(params *SwapParameters) { - params.mode = mode - } -} - -func WithThreshold(payment, disconnect int) SwapOption { - return func(params *SwapParameters) { - params.disconnectThreshold = disconnect - params.paymentThreshold = payment - } -} - -func DefaultOptions() []SwapOption { - return []SwapOption{ - WithMode(SoftMode), - WithThreshold(100, -100), - } -} diff --git a/waku/v2/protocol/swap/waku_swap_option_test.go b/waku/v2/protocol/swap/waku_swap_option_test.go deleted file mode 100644 index f1a010db..00000000 --- a/waku/v2/protocol/swap/waku_swap_option_test.go +++ /dev/null @@ -1,24 +0,0 @@ -package swap - -import ( - "testing" - - "github.com/stretchr/testify/require" -) - -func TestSwapOption(t *testing.T) { - options := []SwapOption{ - WithMode(SoftMode), - WithThreshold(10, 0), - } - - params := &SwapParameters{} - - for _, opt := range options { - opt(params) - } - - require.Equal(t, SoftMode, params.mode) - require.Equal(t, 10, params.paymentThreshold) - require.Equal(t, 0, params.disconnectThreshold) -} diff --git a/waku/v2/protocol/swap/waku_swap_test.go b/waku/v2/protocol/swap/waku_swap_test.go deleted file mode 100644 index 6c0e4195..00000000 --- a/waku/v2/protocol/swap/waku_swap_test.go +++ /dev/null @@ -1,21 +0,0 @@ -package swap - -import ( - "testing" - - "github.com/stretchr/testify/require" - "github.com/waku-org/go-waku/waku/v2/utils" -) - -func TestSwapCreditDebit(t *testing.T) { - swap := NewWakuSwap(utils.Logger(), []SwapOption{ - WithMode(SoftMode), - WithThreshold(0, 0), - }...) - - swap.Credit("1", 1) - require.Equal(t, -1, swap.Accounting["1"]) - - swap.Debit("1", 2) - require.Equal(t, 1, swap.Accounting["1"]) -}