Skip to content

Commit

Permalink
Add missing imports and move function
Browse files Browse the repository at this point in the history
Some imports and functions were missed out in the move towards
separating the protocol into another file. Fixes chris-belcher#176
  • Loading branch information
chris-belcher committed Jan 14, 2020
1 parent a1acc2e commit 7cc939b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
19 changes: 0 additions & 19 deletions electrumpersonalserver/server/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import electrumpersonalserver.server.hashes as hashes
import electrumpersonalserver.server.deterministicwallet as deterministicwallet
import electrumpersonalserver.server.transactionmonitor as transactionmonitor
import electrumpersonalserver.server.peertopeer as peertopeer
from electrumpersonalserver.server.electrumprotocol import (
SERVER_VERSION_NUMBER,
ElectrumProtocol,
Expand All @@ -28,24 +27,6 @@
## global variables are actually mutable lists
bestblockhash = [None]

def get_tor_hostport():
# Probable ports for Tor to listen at
host = "127.0.0.1"
ports = [9050, 9150]
for port in ports:
try:
s = (socket._socketobject if hasattr(socket, "_socketobject")
else socket.socket)(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(0.1)
s.connect((host, port))
# Tor responds uniquely to HTTP-like requests
s.send(b"GET\n")
if b"Tor is not an HTTP Proxy" in s.recv(1024):
return (host, port)
except socket.error:
pass
return None

def on_heartbeat_listening(txmonitor):
logger = logging.getLogger('ELECTRUMPERSONALSERVER')
logger.debug("on heartbeat listening")
Expand Down
21 changes: 21 additions & 0 deletions electrumpersonalserver/server/electrumprotocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import struct
import tempfile
import socket
from collections import defaultdict

from electrumpersonalserver.server.hashes import (
Expand All @@ -13,6 +14,7 @@
bytes_fmt
)
from .jsonrpc import JsonRpc, JsonRpcError
import electrumpersonalserver.server.peertopeer as peertopeer
from electrumpersonalserver.server.merkleproof import (
convert_core_to_electrum_merkle_proof
)
Expand Down Expand Up @@ -48,6 +50,25 @@
"""

def get_tor_hostport():
# Probable ports for Tor to listen at
host = "127.0.0.1"
ports = [9050, 9150]
for port in ports:
try:
s = (socket._socketobject if hasattr(socket, "_socketobject")
else socket.socket)(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(0.1)
s.connect((host, port))
# Tor responds uniquely to HTTP-like requests
s.send(b"GET\n")
if b"Tor is not an HTTP Proxy" in s.recv(1024):
return (host, port)
except socket.error:
pass
return None


def get_block_header(rpc, blockhash, raw=False):
rpc_head = rpc.call("getblockheader", [blockhash])
if "previousblockhash" in rpc_head:
Expand Down

0 comments on commit 7cc939b

Please sign in to comment.