@@ -136,22 +136,26 @@ func (td *testData) init(msgCount int) error {
136
136
msgAddr := pot .RandomAddress () // we choose message addresses randomly
137
137
td .recipientAddresses = append (td .recipientAddresses , msgAddr .Bytes ())
138
138
smallestPo := 256
139
- var targets [] enode.ID
140
- var closestPO int
139
+ var target enode.ID
140
+ var closestPO int = - 1
141
141
142
142
// loop through all nodes and find the required and allowed recipients of each message
143
143
// (for more information, please see the comment to the main test function)
144
144
for _ , nod := range td .sim .Net .GetNodes () {
145
145
po , _ := pof (td .recipientAddresses [i ], td .nodeAddresses [nod .ID ()], 0 )
146
146
depth := td .kademlias [nod .ID ()].NeighbourhoodDepth ()
147
147
148
- // only nodes with closest IDs (wrt the msg address) will be required recipients
148
+ // only the node that is the closest in terms of distance is the required recipient
149
149
if po > closestPO {
150
150
closestPO = po
151
- targets = nil
152
- targets = append (targets , nod .ID ())
151
+ target = nod .ID ()
153
152
} else if po == closestPO {
154
- targets = append (targets , nod .ID ())
153
+ compareResult , err := pot .DistanceCmp (msgAddr .Bytes (), td .nodeAddresses [nod .ID ()], td .nodeAddresses [target ])
154
+ if err != nil {
155
+ return err
156
+ } else if compareResult == 1 {
157
+ target = nod .ID ()
158
+ }
155
159
}
156
160
157
161
if po >= depth {
@@ -163,15 +167,20 @@ func (td *testData) init(msgCount int) error {
163
167
if po < smallestPo {
164
168
smallestPo = po
165
169
td .senders [i ] = nod .ID ()
170
+ } else if po == smallestPo {
171
+ compareResult , err := pot .DistanceCmp (msgAddr .Bytes (), td .nodeAddresses [nod .ID ()], td.nodeAddresses [td.senders [i ]])
172
+ if err != nil {
173
+ return err
174
+ } else if compareResult == - 1 {
175
+ td .senders [i ] = nod .ID ()
176
+ }
166
177
}
167
178
}
168
179
169
- td .requiredMsgCount += len (targets )
170
- for _ , id := range targets {
171
- td .requiredMsgs [id ] = append (td .requiredMsgs [id ], uint64 (i ))
172
- }
180
+ td .requiredMsgCount += 1
181
+ td .requiredMsgs [target ] = append (td .requiredMsgs [target ], uint64 (i ))
173
182
174
- log .Debug ("nn for msg" , "targets" , len ( targets ), " msgidx" , i , "msg" , common .Bytes2Hex (msgAddr [:8 ]), "sender" , td .senders [i ], "senderpo" , smallestPo )
183
+ log .Debug ("nn for msg" , "msgidx" , i , "msg" , common .Bytes2Hex (msgAddr [:8 ]), "sender" , td .senders [i ], "senderpo" , smallestPo , "closestAddr" , td . nodeAddresses [ target ] )
175
184
}
176
185
log .Debug ("recipientAddresses to receive" , "count" , td .requiredMsgCount )
177
186
return nil
@@ -441,12 +450,6 @@ func newProxServices(td *testData, allowRaw bool, handlerContextFuncs map[Topic]
441
450
deregisters = append (deregisters , ps .Register (& tpc , hndlrFunc (td , ctx .Config )))
442
451
}
443
452
444
- // if handshake mode is set, add the controller
445
- // TODO: This should be hooked to the handshake test file
446
- if useHandshake {
447
- SetHandshakeController (ps , NewHandshakeParams ())
448
- }
449
-
450
453
// we expose some api calls for cheating
451
454
ps .addAPI (rpc.API {
452
455
Namespace : "psstest" ,
0 commit comments