mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-17 19:03:42 +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:
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 .primitives import Secret, PrivateKey, PublicKey
|
||||
from hashlib import sha256
|
||||
from typing import Tuple
|
||||
import coincurve
|
||||
import os
|
||||
import socket
|
||||
import socks
|
||||
import struct
|
||||
import threading
|
||||
|
||||
@ -318,7 +320,8 @@ class LightningServerSocket(socket.socket):
|
||||
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:
|
||||
remote_pubkey = PublicKey(node_id)
|
||||
elif isinstance(node_id, ec.EllipticCurvePublicKey):
|
||||
@ -329,7 +332,13 @@ def connect(local_privkey, node_id, host, port=9735):
|
||||
raise ValueError(
|
||||
"node_id must be either a 33 byte array, or a PublicKey"
|
||||
)
|
||||
conn = socket.create_connection((host, port))
|
||||
|
||||
if socks_addr is None:
|
||||
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,
|
||||
is_initiator=True)
|
||||
lconn.shake()
|
||||
|
@ -3,3 +3,4 @@ cryptography==3.2
|
||||
coincurve==13.0.0
|
||||
base58==1.0.2
|
||||
mypy
|
||||
pysocks==1.7.*
|
||||
|
Loading…
Reference in New Issue
Block a user