Skip to content
Snippets Groups Projects
Commit a2dcd465 authored by inso's avatar inso
Browse files

Renamed "Person.name" to "Person.uid"

parent e0fa6196
No related branches found
No related tags found
No related merge requests found
...@@ -45,7 +45,7 @@ class Graph(object): ...@@ -45,7 +45,7 @@ class Graph(object):
""" """
path = list() path = list()
logging.debug("path between %s to %s..." % (from_person.name, to_person.name)) logging.debug("path between %s to %s..." % (from_person.uid, to_person.uid))
if from_person.pubkey not in self._graph.keys(): if from_person.pubkey not in self._graph.keys():
self.add_person(from_person) self.add_person(from_person)
certifier_list = from_person.certifiers_of(self.community) certifier_list = from_person.certifiers_of(self.community)
...@@ -79,7 +79,7 @@ class Graph(object): ...@@ -79,7 +79,7 @@ class Graph(object):
# functions keywords args are persistent... Need to reset it with None trick # functions keywords args are persistent... Need to reset it with None trick
connected = connected or (list() and (connected is None)) connected = connected or (list() and (connected is None))
done = done or (list() and (done is None)) done = done or (list() and (done is None))
logging.debug("search %s in " % person.name) logging.debug("search %s in " % person.uid)
logging.debug([self._graph[pubkey]['text'] for pubkey in connected]) logging.debug([self._graph[pubkey]['text'] for pubkey in connected])
# for each pubkey connected... # for each pubkey connected...
for pubkey in tuple(connected): for pubkey in tuple(connected):
...@@ -261,7 +261,7 @@ class Graph(object): ...@@ -261,7 +261,7 @@ class Graph(object):
self._graph[person.pubkey] = { self._graph[person.pubkey] = {
'id': person.pubkey, 'id': person.pubkey,
'arcs': arcs, 'arcs': arcs,
'text': person.name, 'text': person.uid,
'tooltip': person.pubkey, 'tooltip': person.pubkey,
'status': status, 'status': status,
'connected': connected 'connected': connected
......
...@@ -61,7 +61,14 @@ class Network(QObject): ...@@ -61,7 +61,14 @@ class Network(QObject):
node = Node.from_json(self.currency, data) node = Node.from_json(self.currency, data)
self._nodes.append(node) self._nodes.append(node)
logging.debug("Loading : {:}".format(data['pubkey'])) logging.debug("Loading : {:}".format(data['pubkey']))
for n in self._nodes:
try:
n.changed.disconnect()
except TypeError:
pass
self._nodes = self.crawling() self._nodes = self.crawling()
for n in self._nodes:
n.changed.connect(self.nodes_changed)
@classmethod @classmethod
def from_json(cls, currency, json_data): def from_json(cls, currency, json_data):
...@@ -161,6 +168,15 @@ class Network(QObject): ...@@ -161,6 +168,15 @@ class Network(QObject):
for node in [n for n in nodes if n.state == Node.ONLINE]: for node in [n for n in nodes if n.state == Node.ONLINE]:
node.check_sync(block_max) node.check_sync(block_max)
for node in self._nodes:
if node.last_change + 3600 < time.time() and \
node.state in (Node.OFFLINE, Node.CORRUPTED):
try:
node.changed.disconnect()
except TypeError:
pass
self._nodes.remove(node)
#TODO: Offline nodes for too long have to be removed #TODO: Offline nodes for too long have to be removed
#TODO: Corrupted nodes should maybe be removed faster ? #TODO: Corrupted nodes should maybe be removed faster ?
......
...@@ -33,7 +33,8 @@ class Node(QObject): ...@@ -33,7 +33,8 @@ class Node(QObject):
changed = pyqtSignal() changed = pyqtSignal()
def __init__(self, currency, endpoints, uid, pubkey, block, state): def __init__(self, currency, endpoints, uid, pubkey, block,
state, last_change):
''' '''
Constructor Constructor
''' '''
...@@ -45,6 +46,7 @@ class Node(QObject): ...@@ -45,6 +46,7 @@ class Node(QObject):
self._state = state self._state = state
self._neighbours = [] self._neighbours = []
self._currency = currency self._currency = currency
self._last_change = last_change
@classmethod @classmethod
def from_address(cls, currency, address, port): def from_address(cls, currency, address, port):
...@@ -65,7 +67,8 @@ class Node(QObject): ...@@ -65,7 +67,8 @@ class Node(QObject):
if peer.currency != currency: if peer.currency != currency:
raise InvalidNodeCurrency(peer.currency, currency) raise InvalidNodeCurrency(peer.currency, currency)
node = cls(peer.currency, peer.endpoints, "", peer.pubkey, 0, Node.ONLINE) node = cls(peer.currency, peer.endpoints, "", peer.pubkey, 0,
Node.ONLINE, time.time())
node.refresh_state() node.refresh_state()
return node return node
...@@ -82,7 +85,8 @@ class Node(QObject): ...@@ -82,7 +85,8 @@ class Node(QObject):
if peer.currency != currency: if peer.currency != currency:
raise InvalidNodeCurrency(peer.currency, currency) raise InvalidNodeCurrency(peer.currency, currency)
node = cls(peer.currency, peer.endpoints, "", "", 0, Node.ONLINE) node = cls(peer.currency, peer.endpoints, "", "", 0,
Node.ONLINE, time.time())
node.refresh_state() node.refresh_state()
return node return node
...@@ -91,6 +95,7 @@ class Node(QObject): ...@@ -91,6 +95,7 @@ class Node(QObject):
endpoints = [] endpoints = []
uid = "" uid = ""
pubkey = "" pubkey = ""
last_change = time.time()
for endpoint_data in data['endpoints']: for endpoint_data in data['endpoints']:
endpoints.append(Endpoint.from_inline(endpoint_data)) endpoints.append(Endpoint.from_inline(endpoint_data))
...@@ -98,20 +103,25 @@ class Node(QObject): ...@@ -98,20 +103,25 @@ class Node(QObject):
if currency in data: if currency in data:
currency = data['currency'] currency = data['currency']
if uid in data: if 'uid' in data:
uid = data['uid'] uid = data['uid']
if pubkey in data: if 'pubkey' in data:
pubkey = data['pubkey'] pubkey = data['pubkey']
node = cls(currency, endpoints, uid, pubkey, 0, Node.ONLINE) if 'last_change' in data:
last_change = data['last_change']
node = cls(currency, endpoints, uid, pubkey, 0,
Node.ONLINE, last_change)
node.refresh_state() node.refresh_state()
return node return node
def jsonify(self): def jsonify(self):
data = {'pubkey': self._pubkey, data = {'pubkey': self._pubkey,
'uid': self._uid, 'uid': self._uid,
'currency': self._currency} 'currency': self._currency,
'last_change': self._last_change}
endpoints = [] endpoints = []
for e in self._endpoints: for e in self._endpoints:
endpoints.append(e.inline()) endpoints.append(e.inline())
...@@ -146,11 +156,20 @@ class Node(QObject): ...@@ -146,11 +156,20 @@ class Node(QObject):
def uid(self): def uid(self):
return self._uid return self._uid
@property
def last_change(self):
return self._last_change
def _change_state(self, new_state):
if self.state != new_state:
self._last_change = time.time()
self._state = new_state
def check_sync(self, block): def check_sync(self, block):
if self._block < block: if self._block < block:
self._state = Node.DESYNCED self._change_state(Node.DESYNCED)
else: else:
self._state = Node.ONLINE self._change_state(Node.ONLINE)
def _request_uid(self): def _request_uid(self):
uid = "" uid = ""
...@@ -189,14 +208,14 @@ class Node(QObject): ...@@ -189,14 +208,14 @@ class Node(QObject):
if '404' in e: if '404' in e:
block_number = 0 block_number = 0
except RequestException: except RequestException:
self._state = Node.OFFLINE self._change_state(Node.OFFLINE)
emit_change = True emit_change = True
# If not is offline, do not refresh last data # If not is offline, do not refresh last data
if self._state != Node.OFFLINE: if self.state != Node.OFFLINE:
# If not changed its currency, consider it corrupted # If not changed its currency, consider it corrupted
if node_currency != self._currency: if node_currency != self._currency:
self.state = Node.CORRUPTED self._change_state(Node.CORRUPTED)
emit_change = True emit_change = True
else: else:
node_uid = self._request_uid() node_uid = self._request_uid()
...@@ -234,7 +253,7 @@ class Node(QObject): ...@@ -234,7 +253,7 @@ class Node(QObject):
if self.pubkey not in [n.pubkey for n in found_nodes]: if self.pubkey not in [n.pubkey for n in found_nodes]:
# if node is corrupted remove it # if node is corrupted remove it
if self._state != Node.CORRUPTED: if self.state != Node.CORRUPTED:
found_nodes.append(self) found_nodes.append(self)
try: try:
logging.debug(self.neighbours) logging.debug(self.neighbours)
...@@ -252,7 +271,7 @@ class Node(QObject): ...@@ -252,7 +271,7 @@ class Node(QObject):
traversed_pubkeys, interval) traversed_pubkeys, interval)
time.sleep(interval) time.sleep(interval)
except RequestException as e: except RequestException as e:
self._state = Node.OFFLINE self._change_state(Node.OFFLINE)
def __str__(self): def __str__(self):
return ','.join([str(self.pubkey), str(self.endpoint.server), str(self.endpoint.port), str(self.block), return ','.join([str(self.pubkey), str(self.endpoint.server), str(self.endpoint.port), str(self.block),
......
...@@ -70,19 +70,19 @@ class cached(object): ...@@ -70,19 +70,19 @@ class cached(object):
#TODO: Change Person to Identity ? #TODO: Change Person to Identity ?
class Person(object): class Person(object):
''' '''
A person with a name and a pubkey A person with a uid and a pubkey
''' '''
_instances = {} _instances = {}
def __init__(self, name, pubkey, cache): def __init__(self, uid, pubkey, cache):
''' '''
Initializing a person object. Initializing a person object.
:param str name: The person name, also known as its uid on the network :param str uid: The person uid, also known as its uid on the network
:param str pubkey: The person pubkey :param str pubkey: The person pubkey
:param cache: The last returned values of the person properties. :param cache: The last returned values of the person properties.
''' '''
self.name = name self.uid = uid
self.pubkey = pubkey self.pubkey = pubkey
self._cache = cache self._cache = cache
self._cache_mutex = QMutex() self._cache_mutex = QMutex()
...@@ -118,9 +118,9 @@ class Person(object): ...@@ -118,9 +118,9 @@ class Person(object):
for uid in uids: for uid in uids:
if uid["meta"]["timestamp"] > timestamp: if uid["meta"]["timestamp"] > timestamp:
timestamp = uid["meta"]["timestamp"] timestamp = uid["meta"]["timestamp"]
name = uid["uid"] uid = uid["uid"]
person = cls(name, pubkey, {}) person = cls(uid, pubkey, {})
Person._instances[pubkey] = person Person._instances[pubkey] = person
logging.debug("{0}".format(Person._instances.keys())) logging.debug("{0}".format(Person._instances.keys()))
return person return person
...@@ -130,18 +130,18 @@ class Person(object): ...@@ -130,18 +130,18 @@ class Person(object):
def from_metadata(cls, metadata): def from_metadata(cls, metadata):
''' '''
Get a person from a metadata dict. Get a person from a metadata dict.
A metadata dict has a 'text' key corresponding to the person name, A metadata dict has a 'text' key corresponding to the person uid,
and a 'id' key corresponding to the person pubkey. and a 'id' key corresponding to the person pubkey.
:param dict metadata: The person metadata :param dict metadata: The person metadata
:return: A new person if pubkey wasn't knwon, else the existing instance. :return: A new person if pubkey wasn't knwon, else the existing instance.
''' '''
name = metadata['text'] uid = metadata['text']
pubkey = metadata['id'] pubkey = metadata['id']
if pubkey in Person._instances: if pubkey in Person._instances:
return Person._instances[pubkey] return Person._instances[pubkey]
else: else:
person = cls(name, pubkey, {}) person = cls(uid, pubkey, {})
Person._instances[pubkey] = person Person._instances[pubkey] = person
return person return person
...@@ -157,13 +157,16 @@ class Person(object): ...@@ -157,13 +157,16 @@ class Person(object):
if pubkey in Person._instances: if pubkey in Person._instances:
return Person._instances[pubkey] return Person._instances[pubkey]
else: else:
name = json_data['name'] if 'name' in json_data:
uid = json_data['name']
else:
uid = json_data['uid']
if 'cache' in json_data: if 'cache' in json_data:
cache = json_data['cache'] cache = json_data['cache']
else: else:
cache = {} cache = {}
person = cls(name, pubkey, cache) person = cls(uid, pubkey, cache)
Person._instances[pubkey] = person Person._instances[pubkey] = person
return person return person
...@@ -185,14 +188,14 @@ class Person(object): ...@@ -185,14 +188,14 @@ class Person(object):
for uid in uids: for uid in uids:
if uid["meta"]["timestamp"] > timestamp: if uid["meta"]["timestamp"] > timestamp:
timestamp = uid["meta"]["timestamp"] timestamp = uid["meta"]["timestamp"]
name = uid["uid"] uid = uid["uid"]
signature = uid["self"] signature = uid["self"]
return SelfCertification(PROTOCOL_VERSION, return SelfCertification(PROTOCOL_VERSION,
community.currency, community.currency,
self.pubkey, self.pubkey,
timestamp, timestamp,
name, uid,
signature) signature)
raise PersonNotFoundError(self.pubkey, community.name) raise PersonNotFoundError(self.pubkey, community.name)
...@@ -376,7 +379,7 @@ class Person(object): ...@@ -376,7 +379,7 @@ class Person(object):
Get the community as dict in json format. Get the community as dict in json format.
:return: The community as a dict in json format :return: The community as a dict in json format
''' '''
data = {'name': self.name, data = {'uid': self.uid,
'pubkey': self.pubkey, 'pubkey': self.pubkey,
'cache': self._cache} 'cache': self._cache}
return data return data
...@@ -28,7 +28,7 @@ class CertificationDialog(QDialog, Ui_CertificationDialog): ...@@ -28,7 +28,7 @@ class CertificationDialog(QDialog, Ui_CertificationDialog):
self.combo_community.addItem(community.currency) self.combo_community.addItem(community.currency)
for contact in certifier.contacts: for contact in certifier.contacts:
self.combo_contact.addItem(contact.name) self.combo_contact.addItem(contact['name'])
def accept(self): def accept(self):
if self.radio_contact.isChecked(): if self.radio_contact.isChecked():
......
...@@ -21,7 +21,7 @@ class MemberDialog(QDialog, Ui_DialogMember): ...@@ -21,7 +21,7 @@ class MemberDialog(QDialog, Ui_DialogMember):
self.community = community self.community = community
self.account = account self.account = account
self.person = person self.person = person
self.label_uid.setText(person.name) self.label_uid.setText(person.uid)
join_date = self.person.get_join_date(self.community) join_date = self.person.get_join_date(self.community)
join_date = datetime.datetime.fromtimestamp(join_date).strftime("%d/%m/%Y %I:%M") join_date = datetime.datetime.fromtimestamp(join_date).strftime("%d/%m/%Y %I:%M")
......
...@@ -49,4 +49,3 @@ class NetworkTabWidget(QWidget, Ui_NetworkTabWidget): ...@@ -49,4 +49,3 @@ class NetworkTabWidget(QWidget, Ui_NetworkTabWidget):
def showEvent(self, event): def showEvent(self, event):
super().showEvent(event) super().showEvent(event)
self.watcher_thread.start() self.watcher_thread.start()
...@@ -96,7 +96,7 @@ class MembersTableModel(QAbstractTableModel): ...@@ -96,7 +96,7 @@ class MembersTableModel(QAbstractTableModel):
join_date = self.community.get_block(join_block).mediantime join_date = self.community.get_block(join_block).mediantime
parameters = self.community.parameters parameters = self.community.parameters
expiration_date = join_date + parameters['sigValidity'] expiration_date = join_date + parameters['sigValidity']
return (person.name, pubkey, join_date, expiration_date) return (person.uid, pubkey, join_date, expiration_date)
def data(self, index, role): def data(self, index, role):
if role == Qt.DisplayRole: if role == Qt.DisplayRole:
......
...@@ -56,9 +56,9 @@ class TxFilterProxyModel(QSortFilterProxyModel): ...@@ -56,9 +56,9 @@ class TxFilterProxyModel(QSortFilterProxyModel):
elif right_data == "": elif right_data == "":
return self.sortOrder() == Qt.AscendingOrder return self.sortOrder() == Qt.AscendingOrder
if left_data.__class__ is Person: if left_data.__class__ is Person:
left_data = left_data.name left_data = left_data.uid
if right_data.__class__ is Person: if right_data.__class__ is Person:
right_data = right_data.name right_data = right_data.uid
return (left_data < right_data) return (left_data < right_data)
...@@ -71,7 +71,7 @@ class TxFilterProxyModel(QSortFilterProxyModel): ...@@ -71,7 +71,7 @@ class TxFilterProxyModel(QSortFilterProxyModel):
if role == Qt.DisplayRole: if role == Qt.DisplayRole:
if source_index.column() == self.sourceModel().column_types.index('uid'): if source_index.column() == self.sourceModel().column_types.index('uid'):
if source_data.__class__ == Person: if source_data.__class__ == Person:
tx_person = source_data.name tx_person = source_data.uid
else: else:
tx_person = "pub:{0}".format(source_data[:5]) tx_person = "pub:{0}".format(source_data[:5])
source_data = tx_person source_data = tx_person
...@@ -178,10 +178,8 @@ class HistoryTableModel(QAbstractTableModel): ...@@ -178,10 +178,8 @@ class HistoryTableModel(QAbstractTableModel):
comment = transfer.txdoc.comment comment = transfer.txdoc.comment
pubkey = transfer.metadata['issuer'] pubkey = transfer.metadata['issuer']
try: try:
#sender = Person.lookup(pubkey, self.community).name
sender = Person.lookup(pubkey, self.community) sender = Person.lookup(pubkey, self.community)
except PersonNotFoundError: except PersonNotFoundError:
#sender = "pub:{0}".format(pubkey[:5])
sender = pubkey sender = pubkey
date_ts = transfer.metadata['time'] date_ts = transfer.metadata['time']
...@@ -196,7 +194,6 @@ class HistoryTableModel(QAbstractTableModel): ...@@ -196,7 +194,6 @@ class HistoryTableModel(QAbstractTableModel):
comment = transfer.txdoc.comment comment = transfer.txdoc.comment
pubkey = transfer.metadata['receiver'] pubkey = transfer.metadata['receiver']
try: try:
#receiver = Person.lookup(pubkey, self.community).name
receiver = Person.lookup(pubkey, self.community) receiver = Person.lookup(pubkey, self.community)
except PersonNotFoundError: except PersonNotFoundError:
#receiver = "pub:{0}".format(pubkey[:5]) #receiver = "pub:{0}".format(pubkey[:5])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment