mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-15 17:30:01 +00:00
42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
|
|
||
|
import struct
|
||
|
|
||
|
class LeaseInfo:
|
||
|
def __init__(self, owner_num=None, renew_secret=None, cancel_secret=None,
|
||
|
expiration_time=None, nodeid=None):
|
||
|
self.owner_num = owner_num
|
||
|
self.renew_secret = renew_secret
|
||
|
self.cancel_secret = cancel_secret
|
||
|
self.expiration_time = expiration_time
|
||
|
if nodeid is not None:
|
||
|
assert isinstance(nodeid, str)
|
||
|
assert len(nodeid) == 20
|
||
|
self.nodeid = nodeid
|
||
|
|
||
|
def from_immutable_data(self, data):
|
||
|
(self.owner_num,
|
||
|
self.renew_secret,
|
||
|
self.cancel_secret,
|
||
|
self.expiration_time) = struct.unpack(">L32s32sL", data)
|
||
|
self.nodeid = None
|
||
|
return self
|
||
|
def to_immutable_data(self):
|
||
|
return struct.pack(">L32s32sL",
|
||
|
self.owner_num,
|
||
|
self.renew_secret, self.cancel_secret,
|
||
|
int(self.expiration_time))
|
||
|
|
||
|
def to_mutable_data(self):
|
||
|
return struct.pack(">LL32s32s20s",
|
||
|
self.owner_num,
|
||
|
int(self.expiration_time),
|
||
|
self.renew_secret, self.cancel_secret,
|
||
|
self.nodeid)
|
||
|
def from_mutable_data(self, data):
|
||
|
(self.owner_num,
|
||
|
self.expiration_time,
|
||
|
self.renew_secret, self.cancel_secret,
|
||
|
self.nodeid) = struct.unpack(">LL32s32s20s", data)
|
||
|
return self
|
||
|
|