@@ -71,11 +71,6 @@ func (network *Network) CheckNodesAwaitingResponse() {
71
71
72
72
for e := network .awaitingResponseList .Front (); e != nil ; e = e .Next () {
73
73
nodeTimestamp := e .Value .(AwaitingResponseObject ).timestamp
74
- fmt .Println (nodeTimestamp )
75
- fmt .Println (currentTime )
76
- fmt .Println (currentTime - nodeTimestamp )
77
- fmt .Println (e .Value .(AwaitingResponseObject ).oldNode )
78
- fmt .Println (e .Value .(AwaitingResponseObject ).newNode )
79
74
if (currentTime - nodeTimestamp ) >= 5 { //If 5 seconds or more have passed
80
75
network .routingTable .RemoveContact (e .Value .(AwaitingResponseObject ).oldNode )
81
76
network .routingTable .AddContact (e .Value .(AwaitingResponseObject ).newNode )
@@ -178,9 +173,8 @@ func (network *Network) ListenHandler(receivedData []byte, connection *net.UDPCo
178
173
case "OK" :
179
174
responseType = "NONE"
180
175
case "STORE" :
181
- key := network .AddToStore (decodedData .Content )
176
+ network .AddToStore (decodedData .Content )
182
177
responseType = "OK"
183
- responseContent = string (key [:])
184
178
case "FINDVALUE" :
185
179
dataFound , data := network .LookForData (decodedData .Content )
186
180
if dataFound {
@@ -207,7 +201,7 @@ func (network *Network) ListenHandler(receivedData []byte, connection *net.UDPCo
207
201
208
202
case "FINDNODE_RESPONSE" :
209
203
network .lookUpContactResponse = LookUpContactResponse {decodedData .Content }
210
- fmt .Println (network .lookUpContactResponse )
204
+ // fmt.Println(network.lookUpContactResponse)
211
205
responseType = "NONE"
212
206
213
207
case "PONG" :
@@ -224,15 +218,24 @@ func (network *Network) ListenHandler(receivedData []byte, connection *net.UDPCo
224
218
}
225
219
}
226
220
227
- func (network * Network ) AddToStore (message string ) KademliaID {
221
+ func (network * Network ) AddToStore (message string ) {
228
222
hxMsg := network .MakeHash (message )
229
- network .routingTable .me .KeyValueStore [string (hxMsg [:])] = message
230
- return hxMsg
223
+
224
+ hxMsgJSON , err := json .Marshal (hxMsg )
225
+ if err != nil {
226
+ fmt .Println (err )
227
+ }
228
+
229
+ network .routingTable .me .KeyValueStore [string (hxMsgJSON )] = message
231
230
}
232
231
233
232
func (network * Network ) LookForData (hash string ) (bool , string ) {
234
233
for key , element := range network .routingTable .me .KeyValueStore {
235
- if string (key [:]) == hash {
234
+ fmt .Println ("LookForData loop" )
235
+ fmt .Println ("Key: " + key )
236
+ fmt .Println ("Hash: " + hash )
237
+
238
+ if key == hash {
236
239
fmt .Println ("LookForData found element: " + element )
237
240
return true , element
238
241
}
@@ -241,23 +244,14 @@ func (network *Network) LookForData(hash string) (bool, string) {
241
244
}
242
245
243
246
func (network * Network ) MakeHash (message string ) KademliaID {
244
- hash := sha1 .Sum ([]byte (message ))
245
- fmt .Println ("MAKEHASH------" )
246
- fmt .Println (hash )
247
-
248
- return hash
247
+ hash := sha1 .Sum ([]byte (message ))
248
+ return hash
249
249
}
250
250
251
251
func (network * Network ) storeRPC (message RPC ) {
252
- hash := network .MakeHash (message .Content )
253
- fmt .Printf (string (hash [:]))
254
252
network .SendMessage (message )
255
253
}
256
254
257
- func (network * Network ) idToString (id KademliaID ) string {
258
- return string (id [:])
259
- }
260
-
261
255
func (network * Network ) JSONEncodeLookUpDataResponse (unencodedResponse LookUpDataResponse ) string {
262
256
encoded , err := json .Marshal (unencodedResponse )
263
257
if err != nil {
0 commit comments