@@ -161,10 +161,10 @@ func HandleRequestProof(req Request) {
161
161
CID := req .CID
162
162
hash := req .Hash
163
163
if ipfs .IsPinned (CID ) == true {
164
+ fmt .Println ("Sending proof of access to validation node" )
164
165
validationHash := validation .CreatProofHash (hash , CID )
165
166
SendProof (req , validationHash , hash , localdata .NodeName )
166
167
} else {
167
- fmt .Println ("Sending proof of access to validation node" )
168
168
SendProof (req , hash , req .Seed , localdata .NodeName )
169
169
}
170
170
@@ -474,12 +474,31 @@ func SyncNode(req Request) {
474
474
log .Println ("Pins data:" , req .Pins )
475
475
return
476
476
}
477
+ // Lock to safely read from shared data
477
478
localdata .Lock .Lock ()
478
479
allPins := localdata .PeerCids [req .User ]
479
480
localdata .Lock .Unlock ()
480
- for _ , value := range pins {
481
- allPins = append (allPins , value )
481
+
482
+ // Create a map to use as a set for unique values
483
+ uniquePins := make (map [string ]struct {})
484
+
485
+ // Populate the map with the existing pins
486
+ for _ , pin := range allPins {
487
+ uniquePins [pin ] = struct {}{}
482
488
}
489
+
490
+ // Add new pins to the map, automatically removing duplicates
491
+ for _ , pin := range pins {
492
+ uniquePins [pin ] = struct {}{}
493
+ }
494
+
495
+ // Convert the map keys back into a slice
496
+ allPins = make ([]string , 0 , len (uniquePins ))
497
+ for pin := range uniquePins {
498
+ allPins = append (allPins , pin )
499
+ }
500
+
501
+ // Lock to safely write to shared data
483
502
localdata .Lock .Lock ()
484
503
localdata .PeerCids [req .User ] = allPins
485
504
localdata .PeerSyncSeed [req .Seed ] = localdata .PeerSyncSeed [req .Seed ] + 1
0 commit comments