lunalib 1.6.6__py3-none-any.whl → 1.6.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
lunalib/core/p2p.py
CHANGED
|
@@ -14,9 +14,10 @@ class P2PClient:
|
|
|
14
14
|
Downloads initial state from primary node, then syncs via P2P with periodic validation.
|
|
15
15
|
"""
|
|
16
16
|
|
|
17
|
-
def __init__(self, primary_node_url: str, node_id: Optional[str] = None):
|
|
17
|
+
def __init__(self, primary_node_url: str, node_id: Optional[str] = None, peer_url: Optional[str] = None):
|
|
18
18
|
self.primary_node = primary_node_url
|
|
19
19
|
self.node_id = node_id or self._generate_node_id()
|
|
20
|
+
self.peer_url = peer_url or self._generate_peer_url()
|
|
20
21
|
self.peers = []
|
|
21
22
|
self.last_primary_check = 0
|
|
22
23
|
self.last_peer_update = 0
|
|
@@ -40,6 +41,19 @@ class P2PClient:
|
|
|
40
41
|
timestamp = str(time.time())
|
|
41
42
|
return hashlib.sha256(f"{hostname}{timestamp}".encode()).hexdigest()[:16]
|
|
42
43
|
|
|
44
|
+
def _generate_peer_url(self) -> str:
|
|
45
|
+
"""Generate peer URL (defaults to localhost, should be overridden for public nodes)"""
|
|
46
|
+
import socket
|
|
47
|
+
try:
|
|
48
|
+
# Try to get local IP
|
|
49
|
+
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
50
|
+
s.connect(("8.8.8.8", 80))
|
|
51
|
+
local_ip = s.getsockname()[0]
|
|
52
|
+
s.close()
|
|
53
|
+
return f"http://{local_ip}:8080"
|
|
54
|
+
except:
|
|
55
|
+
return "http://localhost:8080"
|
|
56
|
+
|
|
43
57
|
def start(self):
|
|
44
58
|
"""Start P2P client"""
|
|
45
59
|
if self.is_running:
|
|
@@ -86,6 +100,7 @@ class P2PClient:
|
|
|
86
100
|
try:
|
|
87
101
|
peer_info = {
|
|
88
102
|
'node_id': self.node_id,
|
|
103
|
+
'peer_url': self.peer_url,
|
|
89
104
|
'timestamp': time.time(),
|
|
90
105
|
'capabilities': ['sync', 'relay']
|
|
91
106
|
}
|
|
@@ -97,7 +112,7 @@ class P2PClient:
|
|
|
97
112
|
)
|
|
98
113
|
|
|
99
114
|
if response.status_code == 200:
|
|
100
|
-
print(f"✅ Registered with primary node as peer: {self.node_id}")
|
|
115
|
+
print(f"✅ Registered with primary node as peer: {self.node_id} ({self.peer_url})")
|
|
101
116
|
return True
|
|
102
117
|
else:
|
|
103
118
|
print(f"⚠️ Registration failed: {response.status_code}")
|
|
@@ -261,13 +276,13 @@ class HybridBlockchainClient:
|
|
|
261
276
|
- Periodic validation against primary node
|
|
262
277
|
"""
|
|
263
278
|
|
|
264
|
-
def __init__(self, primary_node_url: str, blockchain_manager, mempool_manager):
|
|
279
|
+
def __init__(self, primary_node_url: str, blockchain_manager, mempool_manager, peer_url: Optional[str] = None):
|
|
265
280
|
self.primary_node = primary_node_url
|
|
266
281
|
self.blockchain = blockchain_manager
|
|
267
282
|
self.mempool = mempool_manager
|
|
268
283
|
|
|
269
284
|
# Initialize P2P client
|
|
270
|
-
self.p2p = P2PClient(primary_node_url)
|
|
285
|
+
self.p2p = P2PClient(primary_node_url, peer_url=peer_url)
|
|
271
286
|
self.p2p.set_callbacks(
|
|
272
287
|
on_new_block=self._handle_new_block,
|
|
273
288
|
on_new_transaction=self._handle_new_transaction,
|
|
@@ -6,7 +6,7 @@ lunalib/core/blockchain.py,sha256=dY_zQXzT8wufrinN8rGlpDTHM_M1yejfKEIm6_s78io,36
|
|
|
6
6
|
lunalib/core/crypto.py,sha256=R_f2sj7ASNnMW8Dtf2LIWTw-vCUjXD33zJPqPcPQVB8,10684
|
|
7
7
|
lunalib/core/daemon.py,sha256=h8I68axWR78I8w5eOrBBQwfTeAxGqOKKW0RtLoQ52yM,16189
|
|
8
8
|
lunalib/core/mempool.py,sha256=itYFGQEuUde0Xh6WXcEz_n8hDsNhxkEAlRQ5g_Qiygg,14845
|
|
9
|
-
lunalib/core/p2p.py,sha256=
|
|
9
|
+
lunalib/core/p2p.py,sha256=cj3dda05oL6W5oMsvJ_HT3U0qr1FL6DR-YI78k3InKg,13784
|
|
10
10
|
lunalib/core/sm2.py,sha256=Eq8Er3XQW5rYJXwaPT5vw5NoVXbSWhyuvjoG1LMo-NQ,23454
|
|
11
11
|
lunalib/core/wallet.py,sha256=RNrEI7_tsaJOLcCJoTy_lLj22bc_bJtoO7iR3C3u7Ls,57435
|
|
12
12
|
lunalib/core/wallet_manager.py,sha256=KK58hrr_xF1vZ4qI6x_BJqrs9XXh5m0XbZYnZmi9yoU,26031
|
|
@@ -27,7 +27,7 @@ lunalib/transactions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hS
|
|
|
27
27
|
lunalib/transactions/security.py,sha256=cQJRasJ37Z8mJo8gt0JJOb0_M9CQ0QScr67y3M_NP4Q,10309
|
|
28
28
|
lunalib/transactions/transactions.py,sha256=3PgyW8gDQwY-gAPGY_T3m7RE_9HzEIOjTf6CWCsOKFY,18151
|
|
29
29
|
lunalib/transactions/validator.py,sha256=FQ-jVjj8VoVTlq65blB_hprAwJOtpc2peYdQk_L2xmg,2730
|
|
30
|
-
lunalib-1.6.
|
|
31
|
-
lunalib-1.6.
|
|
32
|
-
lunalib-1.6.
|
|
33
|
-
lunalib-1.6.
|
|
30
|
+
lunalib-1.6.7.dist-info/METADATA,sha256=XkB0ZGSCQ8QoUy3XSv17UOPTAENS0ZrY1m_H_fBdgZU,774
|
|
31
|
+
lunalib-1.6.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
32
|
+
lunalib-1.6.7.dist-info/top_level.txt,sha256=eLcoOCtOwfvoqUu5g5CNBZB9bdhGXbTwmjuOM7i8ylw,8
|
|
33
|
+
lunalib-1.6.7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|