restrict forwarding of queries to sqrt of neighboring connections. Thanks to 'qtm' for the idea

pull/53/head
Zlatin Balevsky 2020-09-19 17:28:19 +01:00
parent a262c99efe
commit 44af23c162
No known key found for this signature in database
GPG Key ID: A72832072D525E41
1 changed files with 11 additions and 1 deletions

View File

@ -21,6 +21,8 @@ class UltrapeerConnectionManager extends ConnectionManager {
final Map<Destination, PeerConnection> peerConnections = new ConcurrentHashMap() final Map<Destination, PeerConnection> peerConnections = new ConcurrentHashMap()
final Map<Destination, LeafConnection> leafConnections = new ConcurrentHashMap() final Map<Destination, LeafConnection> leafConnections = new ConcurrentHashMap()
private final Random random = new Random()
UltrapeerConnectionManager() {} UltrapeerConnectionManager() {}
@ -44,8 +46,16 @@ class UltrapeerConnectionManager extends ConnectionManager {
if (e.replyTo != me.destination && e.receivedOn != me.destination && if (e.replyTo != me.destination && e.receivedOn != me.destination &&
!leafConnections.containsKey(e.receivedOn)) !leafConnections.containsKey(e.receivedOn))
e.firstHop = false e.firstHop = false
final int connCount = peerConnections.size()
if (connCount == 0)
return
final int treshold = (int)(Math.sqrt(connCount)) + 1
peerConnections.values().each { peerConnections.values().each {
if (e.getReceivedOn() != it.getEndpoint().getDestination()) // 1. do not send query back to originator
// 2. if firstHop forward to everyone
// 3. otherwise to randomized sqrt of neighbors
if (e.getReceivedOn() != it.getEndpoint().getDestination() &&
(e.firstHop || random.nextInt(connCount) < treshold))
it.sendQuery(e) it.sendQuery(e)
} }
} }