mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 23:24:27 +01:00
pyln: Add TOR and SOCKS5 support in pyln.proto.wire.connect
I wanted to talk to TOR-based nodes, so here comes TOR support :-)
This commit is contained in:
committed by
Rusty Russell
parent
25b0dbe7e8
commit
68d08fc7d7
@@ -6,9 +6,11 @@ from cryptography.hazmat.primitives.ciphers.aead import ChaCha20Poly1305
|
|||||||
from cryptography.hazmat.primitives.kdf.hkdf import HKDF
|
from cryptography.hazmat.primitives.kdf.hkdf import HKDF
|
||||||
from .primitives import Secret, PrivateKey, PublicKey
|
from .primitives import Secret, PrivateKey, PublicKey
|
||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
|
from typing import Tuple
|
||||||
import coincurve
|
import coincurve
|
||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
|
import socks
|
||||||
import struct
|
import struct
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
@@ -318,7 +320,8 @@ class LightningServerSocket(socket.socket):
|
|||||||
return (lconn, address)
|
return (lconn, address)
|
||||||
|
|
||||||
|
|
||||||
def connect(local_privkey, node_id, host, port=9735):
|
def connect(local_privkey, node_id, host: str, port: int = 9735,
|
||||||
|
socks_addr: Tuple[str, int] = None):
|
||||||
if isinstance(node_id, bytes) and len(node_id) == 33:
|
if isinstance(node_id, bytes) and len(node_id) == 33:
|
||||||
remote_pubkey = PublicKey(node_id)
|
remote_pubkey = PublicKey(node_id)
|
||||||
elif isinstance(node_id, ec.EllipticCurvePublicKey):
|
elif isinstance(node_id, ec.EllipticCurvePublicKey):
|
||||||
@@ -329,7 +332,13 @@ def connect(local_privkey, node_id, host, port=9735):
|
|||||||
raise ValueError(
|
raise ValueError(
|
||||||
"node_id must be either a 33 byte array, or a PublicKey"
|
"node_id must be either a 33 byte array, or a PublicKey"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if socks_addr is None:
|
||||||
conn = socket.create_connection((host, port))
|
conn = socket.create_connection((host, port))
|
||||||
|
else:
|
||||||
|
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, *socks_addr, True)
|
||||||
|
conn = socks.socksocket()
|
||||||
|
conn.connect((host, port))
|
||||||
lconn = LightningConnection(conn, remote_pubkey, local_privkey,
|
lconn = LightningConnection(conn, remote_pubkey, local_privkey,
|
||||||
is_initiator=True)
|
is_initiator=True)
|
||||||
lconn.shake()
|
lconn.shake()
|
||||||
|
|||||||
@@ -3,3 +3,4 @@ cryptography==3.2
|
|||||||
coincurve==13.0.0
|
coincurve==13.0.0
|
||||||
base58==1.0.2
|
base58==1.0.2
|
||||||
mypy
|
mypy
|
||||||
|
pysocks==1.7.*
|
||||||
|
|||||||
Reference in New Issue
Block a user