diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a8e4be..4abd5d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,3 +5,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] * Fixed #77 - Unexpected type conversion in buckets + * Fixed #78 - load_state does not await bootstrap diff --git a/kademlia/network.py b/kademlia/network.py index fff17ff..debd946 100644 --- a/kademlia/network.py +++ b/kademlia/network.py @@ -211,17 +211,19 @@ class Server: pickle.dump(data, file) @classmethod - def load_state(cls, fname): + async def load_state(cls, fname, port, interface='0.0.0.0'): """ Load the state of this node (the alpha/ksize/id/immediate neighbors) - from a cache file with the given fname. + from a cache file with the given fname and then bootstrap the node + (using the given port/interface to start listening/bootstrapping). """ log.info("Loading state from %s", fname) with open(fname, 'rb') as file: data = pickle.load(file) svr = Server(data['ksize'], data['alpha'], data['id']) + await svr.listen(port, interface) if data['neighbors']: - svr.bootstrap(data['neighbors']) + await svr.bootstrap(data['neighbors']) return svr def save_state_regularly(self, fname, frequency=600):