This commit is contained in:
AtHeartEngineer
2022-09-13 20:27:48 +00:00
parent e21c8640bb
commit 8e9cf1636e
6 changed files with 96 additions and 0 deletions

View File

View File

@@ -0,0 +1,17 @@
# Dandelion Constants
# GossipsubStemMin should be at minimum 1, but recommend setting it to 2 or 3
GossipsubStemMin = 3
# GossipsubStemMax should be set to at least GossipsubStemMin + 1, and would highly discourage setting this to above 10 or 12.
GossipsubStemMax = 8
# Determines how many peers to send a dandelion message to.
# In an ideal case, this should be set to 1, but for redundancy we recommend setting it to 2 in case a peer is malicious or malfunctioning.
numberOfStemPeers = 2
# Highly recommend stemReductionMin be 1, but it could be set to 0
StemReductionMin = 1
# stemReductionMax could be the same value as stemReductionMin if you want a more deterministic, but recommend it be set to stemReductionMin + 1
StemReductionMax = 2

View File

@@ -0,0 +1,20 @@
# Generates a random int between stemMin and stemMax, with fallbacks:
# returns zero if dandelion isn't enable
# If stemMin is undefined or invalid it is set to 2
# if stemMax is undefined or invalid it is set to the minimum value between stemMin + 3 and 10
import math
from random import random
def generateStemLength(stemMin: int, stemMax: int) -> int:
# StemMin should be at minimum 1, but recommend setting it to 2
if (stemMin is None or stemMin < 1):
stemMin = 2
# This is set to a <= and not an < because there should be some randomness in the stem length
if (stemMax is None or stemMax <= stemMin):
stemMax = min(stemMin + 3, 10)
# Returns a random whole number between stemMin and stemMax
return math.floor(random() * (stemMax - stemMin + 1) + stemMin)

View File

@@ -0,0 +1,27 @@
# This function is used when receiving a message that has a stem length, and is used to reduce the stem length for the next hop.
# Reduces the stemLength by a random whole number between stemReductionMin and stemReductionMax. The randomness helps obfuscate the sending source and helps propogate the message via floodsub/classic gossipsub to the network sooner.
import math
from random import random
def reviseStemLength(stemLength: int, stemReductionMin: int, stemReductionMax: int) -> int:
if (stemLength > 0):
# Highly recommend stemReductionMin be 1, but it could be set to 0
if (stemReductionMin is None or stemReductionMin < 0):
stemReductionMin = 1
# stemReductionMax could be the same value as stemReductionMin if you want a more deterministic, but recommend it be set to stemReductionMin + 1
if (stemReductionMax is None or stemReductionMax < stemReductionMin):
stemReductionMax = stemReductionMin + 1
delta = math.floor(random() * (stemReductionMax - stemReductionMin + 1) + stemReductionMin)
newStemLength = stemLength - delta
print(f'REVISING STEM LENGTH: {stemLength} (stemlength) - {delta} (delta) = {newStemLength} (newStemLength)')
if (newStemLength < 0):
newStemLength = 0
return newStemLength
else:
return 0

2
requirements.txt Normal file
View File

@@ -0,0 +1,2 @@
numpy
pandas

30
stemMeasurements.py Normal file
View File

@@ -0,0 +1,30 @@
from dandelion_utils.constants import GossipsubStemMin, GossipsubStemMax, numberOfStemPeers, StemReductionMin, StemReductionMax
from dandelion_utils.generateStemLength import generateStemLength
from dandelion_utils.reviseStemLength import reviseStemLength
import numpy as np
import pandas as pd
def printConstants():
print("CONSTANTS:")
print(" - GossipsubStemMin: {}".format(GossipsubStemMin))
print(" - GossipsubStemMax: {}".format(GossipsubStemMax))
print(" - numberOfStemPeers: {}".format(numberOfStemPeers))
print(" - StemReductionMin: {}".format(StemReductionMin))
print(" - StemReductionMax: {}".format(StemReductionMax))
def main():
# Generate a random initial stem length
stemLength = generateStemLength(GossipsubStemMin, GossipsubStemMax)
print("stemLength: {}".format(stemLength))
newStemLength = reviseStemLength(stemLength, StemReductionMin, StemReductionMax)
print("newStemLength: {}".format(newStemLength))
if __name__ == "__main__":
printConstants()
main()