-
Notifications
You must be signed in to change notification settings - Fork 0
/
sybilresistance.go
56 lines (49 loc) · 1.33 KB
/
sybilresistance.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import(
"net"
)
type SybilResistanceHandler struct{
ps *PuzzlesState
cn *CheckNeighbors
}
//returns whether the gossip packet is allowed or not according to the sybil resistance protocol
func (srh *SybilResistanceHandler) handleGossipPacket(gp *GossipPacket, from *net.UDPAddr)bool{
if gp.NodeID!=srh.ps.MyID && srh.ps.LocalChain.containsValidNodeID(gp.NodeID){
srh.cn.mu1.Lock()
val, ok := srh.cn.activeNeighbors[from.String()]
srh.cn.mu1.Unlock()
if ok{
if val{ // if is active
srh.cn.MsgRecv[from.String()] <- gp.NodeID
//fmt.Println("Received from active",from,gp.NodeID)
if gp.InNode != nil && gp.DigitalSign != nil{
if srh.validatePeer(gp.DigitalSign,gp.NodeID){
srh.cn.mu1.Lock()
_, ok := srh.cn.activeNeighbors[gp.InNode.IPAddr]
if ok{
srh.cn.activeNeighbors[gp.InNode.IPAddr] = false }
srh.cn.mu1.Unlock()
}else{
return false
}
}
return true
}else{
return false
}
}else{
return false
}
//fmt.Println("HEREEE",from,gp.NodeID)
//srh.broadcastBlockChain(from)
//var signed *SignedDocument
//hashA := srh.createHashInactive(gp.NodeID)
//signed = srh.signDocument(hashA)
//fmt.Println("Hash: ",signed)
//srh.validatePeer(signed)
return true
}else{
srh.ps.handleJoining(from)
return false
}
}