Fixed #78 - load_state does not await bootstrap
This commit is contained in:
parent
0be8cd2169
commit
82d50d3967
@ -5,3 +5,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
* Fixed #77 - Unexpected type conversion in buckets
|
* Fixed #77 - Unexpected type conversion in buckets
|
||||||
|
* Fixed #78 - load_state does not await bootstrap
|
||||||
|
@ -211,17 +211,19 @@ class Server:
|
|||||||
pickle.dump(data, file)
|
pickle.dump(data, file)
|
||||||
|
|
||||||
@classmethod
|
@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)
|
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)
|
log.info("Loading state from %s", fname)
|
||||||
with open(fname, 'rb') as file:
|
with open(fname, 'rb') as file:
|
||||||
data = pickle.load(file)
|
data = pickle.load(file)
|
||||||
svr = Server(data['ksize'], data['alpha'], data['id'])
|
svr = Server(data['ksize'], data['alpha'], data['id'])
|
||||||
|
await svr.listen(port, interface)
|
||||||
if data['neighbors']:
|
if data['neighbors']:
|
||||||
svr.bootstrap(data['neighbors'])
|
await svr.bootstrap(data['neighbors'])
|
||||||
return svr
|
return svr
|
||||||
|
|
||||||
def save_state_regularly(self, fname, frequency=600):
|
def save_state_regularly(self, fname, frequency=600):
|
||||||
|
Loading…
Reference in New Issue
Block a user