Skip to content

Commit

Permalink
Merge pull request #965 from kozlovsky/feature/settings-from-dict
Browse files Browse the repository at this point in the history
Add TunnelSettings.from_dict classmethod
  • Loading branch information
qstokkink authored Feb 10, 2021
2 parents 60a34e2 + 32ab188 commit 76da077
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions ipv8/messaging/anonymization/community.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,25 @@ def __init__(self):
# Maximum number of relay_early cells that are allowed to pass a relay.
self.max_relay_early = 8

@classmethod
def from_dict(cls, d):
result = cls()
for k, v in d.items():
setattr(result, k, v)
return result


class TunnelCommunity(Community):

version = b'\x02'
community_id = unhexlify('81ded07332bdc775aa5a46f96de9f8f390bbc9f3')

def __init__(self, *args, **kwargs):
self.settings = kwargs.pop('settings', TunnelSettings())
settings = kwargs.pop('settings', TunnelSettings())
if isinstance(settings, dict):
settings = TunnelSettings.from_dict(settings)
self.settings = settings
self.dht_provider = kwargs.pop('dht_provider', None)
if isinstance(self.settings, dict):
settings = TunnelSettings()
for k, v in self.settings.items():
setattr(settings, k, v)
self.settings = settings

super(TunnelCommunity, self).__init__(*args, **kwargs)

Expand Down

0 comments on commit 76da077

Please sign in to comment.