URI: 
       tMerge branch 'master' of https://github.com/chris-belcher/electrum-personal-server - electrum-personal-server - Maximally lightweight electrum server for a single user
  HTML git clone https://git.parazyd.org/electrum-personal-server
   DIR Log
   DIR Files
   DIR Refs
   DIR README
       ---
   DIR commit b5f95edd7e9ded83c737eaca1e45e8c967dac6ef
   DIR parent 9bd9d7d013bdb0c5713939005d6e15d74693f42b
  HTML Author: chris-belcher <chris-belcher@users.noreply.github.com>
       Date:   Fri,  5 Jul 2019 12:49:35 +0100
       
       Merge branch 'master' of https://github.com/chris-belcher/electrum-personal-server
       
       Diffstat:
         M config.ini_sample                   |       3 ++-
         M electrumpersonalserver/server/comm… |      34 +++++++++++++++++++++++++++++--
       
       2 files changed, 34 insertions(+), 3 deletions(-)
       ---
   DIR diff --git a/config.ini_sample b/config.ini_sample
       t@@ -72,11 +72,12 @@ disable_mempool_fee_histogram = false
        
        # Parameter for broadcasting unconfirmed transactions
        # Options are:
       +# * tor-or-own-node  (use tor if tor is running locally, otherwise own-node)
        # * own-node         (broadcast using the connected full node)
        # * tor              (broadcast to random nodes over tor)
        # * system <cmd> %s  (save transaction to file, and invoke system command
        #                     with file path as parameter %s)
       -broadcast_method = own-node
       +broadcast_method = tor-or-own-node
        
        # For tor broadcasting (broadcast_method = tor) configure
        # the tor proxy host and port below
   DIR diff --git a/electrumpersonalserver/server/common.py b/electrumpersonalserver/server/common.py
       t@@ -5,6 +5,7 @@ import traceback, sys, platform
        from ipaddress import ip_network, ip_address
        import logging
        import tempfile
       +import socket
        
        from electrumpersonalserver.server.jsonrpc import JsonRpc, JsonRpcError
        import electrumpersonalserver.server.hashes as hashes
       t@@ -49,6 +50,24 @@ are_headers_raw = [False]
        bestblockhash = [None]
        txid_blockhash_map = {}
        
       +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 send_response(sock, query, result):
            logger = logging.getLogger('ELECTRUMPERSONALSERVER')
            response = {"jsonrpc": "2.0", "result": result, "id": query["id"]}
       t@@ -241,6 +260,16 @@ def handle_query(sock, line, rpc, txmonitor, disable_mempool_fee_histogram,
                    result = txreport["txid"]
                    logger.info('Broadcasting tx ' + txreport["txid"] + " with " +
                        "broadcast method: " + broadcast_method)
       +            if broadcast_method == "tor-or-own-node":
       +                tor_hostport = get_tor_hostport()
       +                if tor_hostport is not None:
       +                    logger.info("Tor detected at " + str(tor_hostport) +
       +                        ". Broadcasting through tor.")
       +                    broadcast_method = "tor"
       +                else:
       +                    logger.info("Could not detect tor. Broadcasting through " +
       +                        "own node.")
       +                    broadcast_method = "own-node"
                    if broadcast_method == "own-node":
                        if not rpc.call("getnetworkinfo", [])["localrelay"]:
                            error = "Broadcast disabled when using blocksonly"
       t@@ -295,8 +324,9 @@ def handle_query(sock, line, rpc, txmonitor, disable_mempool_fee_histogram,
                    #https://github.com/kyuupichan/electrumx/blob/e92c9bd4861c1e35989ad2773d33e01219d33280/server/mempool.py
                    fee_hist = defaultdict(int)
                    for txid, details in mempool.items():
       -                fee_rate = 1e8*details["fee"] // details["size"]
       -                fee_hist[fee_rate] += details["size"]
       +                size = details["size"] if "size" in details else details["vsize"]
       +                fee_rate = 1e8*details["fee"] // size
       +                fee_hist[fee_rate] += size
                    l = list(reversed(sorted(fee_hist.items())))
                    out = []
                    size = 0