Skip to content

Commit 4c4fcca

Browse files
committed
fix: message reply formating and private rpc logic
1 parent 10319c3 commit 4c4fcca

12 files changed

+337
-99
lines changed

waku.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func main() {
118118
},
119119
&cli.StringFlag{
120120
Name: "nat",
121-
Usage: "TODO",
121+
Usage: "TODO - Not implemented yet.", // This was added so js-waku test don't fail
122122
Destination: &options.NAT,
123123
},
124124
&cli.StringFlag{

waku/v2/node/wakunode2.go

+12-8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"sync"
99
"time"
1010

11+
"github.com/ethereum/go-ethereum/crypto"
1112
"github.com/ethereum/go-ethereum/p2p/enode"
1213
"github.com/libp2p/go-libp2p"
1314
"go.uber.org/zap"
@@ -95,19 +96,24 @@ func defaultStoreFactory(w *WakuNode) store.Store {
9596
func New(ctx context.Context, opts ...WakuNodeOption) (*WakuNode, error) {
9697
params := new(WakuNodeParameters)
9798

98-
ctx, cancel := context.WithCancel(ctx)
99-
10099
params.libP2POpts = DefaultLibP2POptions
101100

102101
opts = append(DefaultWakuNodeOptions, opts...)
103102
for _, opt := range opts {
104103
err := opt(params)
105104
if err != nil {
106-
cancel()
107105
return nil, err
108106
}
109107
}
110108

109+
if params.privKey == nil {
110+
prvKey, err := crypto.GenerateKey()
111+
if err != nil {
112+
return nil, err
113+
}
114+
params.privKey = prvKey
115+
}
116+
111117
if params.enableWSS {
112118
params.libP2POpts = append(params.libP2POpts, libp2p.Transport(ws.New, ws.WithTLSConfig(params.tlsConfig)))
113119
} else if params.enableWS {
@@ -118,28 +124,26 @@ func New(ctx context.Context, opts ...WakuNodeOption) (*WakuNode, error) {
118124
if params.hostAddr == nil {
119125
err := WithHostAddress(&net.TCPAddr{IP: net.ParseIP("0.0.0.0"), Port: 0})(params)
120126
if err != nil {
121-
cancel()
122127
return nil, err
123128
}
124129
}
125130
if len(params.multiAddr) > 0 {
126131
params.libP2POpts = append(params.libP2POpts, libp2p.ListenAddrs(params.multiAddr...))
127132
}
128133

129-
if params.privKey != nil {
130-
params.libP2POpts = append(params.libP2POpts, params.Identity())
131-
}
134+
params.libP2POpts = append(params.libP2POpts, params.Identity())
132135

133136
if params.addressFactory != nil {
134137
params.libP2POpts = append(params.libP2POpts, libp2p.AddrsFactory(params.addressFactory))
135138
}
136139

137140
host, err := libp2p.New(params.libP2POpts...)
138141
if err != nil {
139-
cancel()
140142
return nil, err
141143
}
142144

145+
ctx, cancel := context.WithCancel(ctx)
146+
143147
w := new(WakuNode)
144148
w.bcaster = v2.NewBroadcaster(1024)
145149
w.host = host

waku/v2/rpc/filter.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ func (f *FilterService) GetV1Messages(req *http.Request, args *ContentTopicArgs,
119119
return fmt.Errorf("topic %s not subscribed", args.ContentTopic)
120120
}
121121

122-
reply.Messages = f.messages[args.ContentTopic]
122+
for i := range f.messages[args.ContentTopic] {
123+
*reply = append(*reply, ProtoWakuMessageToRPCWakuMessage(f.messages[args.ContentTopic][i]))
124+
}
125+
123126
f.messages[args.ContentTopic] = make([]*pb.WakuMessage, 0)
124127
return nil
125128
}

waku/v2/rpc/filter_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,13 @@ func TestFilterGetV1Messages(t *testing.T) {
134134
&messagesReply,
135135
)
136136
require.NoError(t, err)
137-
require.Len(t, messagesReply.Messages, 1)
137+
require.Len(t, messagesReply, 1)
138138

139139
err = serviceB.GetV1Messages(
140140
makeRequest(t),
141141
&ContentTopicArgs{"ct"},
142142
&messagesReply,
143143
)
144144
require.NoError(t, err)
145-
require.Len(t, messagesReply.Messages, 0)
145+
require.Len(t, messagesReply, 0)
146146
}

0 commit comments

Comments
 (0)