Browse Source

various whitespace fixes

master
undeath 5 years ago committed by Adam Gibson
parent
commit
dfc82ab130
  1. 30
      jmbase/test/test_commands.py
  2. 4
      jmclient/jmclient/client_protocol.py
  3. 38
      jmclient/test/test_client_protocol.py
  4. 83
      jmdaemon/jmdaemon/daemon_protocol.py
  5. 36
      jmdaemon/test/test_daemon_protocol.py

30
jmbase/test/test_commands.py

@ -92,26 +92,26 @@ class JMTestServerProtocol(JMBaseProtocol):
def on_JM_MAKE_TX(self, nick_list, txhex): def on_JM_MAKE_TX(self, nick_list, txhex):
show_receipt("JMMAKETX", nick_list, txhex) show_receipt("JMMAKETX", nick_list, txhex)
d = self.callRemote(JMSigReceived, d = self.callRemote(JMSigReceived,
nick="dummynick", nick="dummynick",
sig="xxxsig") sig="xxxsig")
self.defaultCallbacks(d) self.defaultCallbacks(d)
#add dummy calls to check message sign and message verify #add dummy calls to check message sign and message verify
d2 = self.callRemote(JMRequestMsgSig, d2 = self.callRemote(JMRequestMsgSig,
nick="dummynickforsign", nick="dummynickforsign",
cmd="command1", cmd="command1",
msg="msgforsign", msg="msgforsign",
msg_to_be_signed="fullmsgforsign", msg_to_be_signed="fullmsgforsign",
hostid="hostid1") hostid="hostid1")
self.defaultCallbacks(d2) self.defaultCallbacks(d2)
d3 = self.callRemote(JMRequestMsgSigVerify, d3 = self.callRemote(JMRequestMsgSigVerify,
msg="msgforverify", msg="msgforverify",
fullmsg="fullmsgforverify", fullmsg="fullmsgforverify",
sig="xxxsigforverify", sig="xxxsigforverify",
pubkey="pubkey1", pubkey="pubkey1",
nick="dummynickforverify", nick="dummynickforverify",
hashlen=4, hashlen=4,
max_encoded=5, max_encoded=5,
hostid="hostid2") hostid="hostid2")
self.defaultCallbacks(d3) self.defaultCallbacks(d3)
d4 = self.callRemote(JMTXBroadcast, tx=b"deadbeef") d4 = self.callRemote(JMTXBroadcast, tx=b"deadbeef")
self.defaultCallbacks(d4) self.defaultCallbacks(d4)

4
jmclient/jmclient/client_protocol.py

@ -443,7 +443,7 @@ class JMMakerClientProtocol(JMClientProtocol):
def on_JM_AUTH_RECEIVED(self, nick, offer, commitment, revelation, amount, def on_JM_AUTH_RECEIVED(self, nick, offer, commitment, revelation, amount,
kphex): kphex):
retval = self.client.on_auth_received(nick, offer, retval = self.client.on_auth_received(nick, offer,
commitment, revelation, amount, kphex) commitment, revelation, amount, kphex)
if not retval[0]: if not retval[0]:
jlog.info("Maker refuses to continue on receiving auth.") jlog.info("Maker refuses to continue on receiving auth.")
else: else:
@ -512,7 +512,7 @@ class JMMakerClientProtocol(JMClientProtocol):
return {"accepted": True} return {"accepted": True}
def tx_match(self, txd): def tx_match(self, txd):
for k,v in self.finalized_offers.items(): for k, v in self.finalized_offers.items():
# Tx considered defined by its output set # Tx considered defined by its output set
if v["txd"].vout == txd.vout: if v["txd"].vout == txd.vout:
offerinfo = v offerinfo = v

38
jmclient/test/test_client_protocol.py

@ -199,8 +199,8 @@ class JMTestServerProtocol(JMBaseProtocol):
orderbook = ["aaaa" for _ in range(15)] orderbook = ["aaaa" for _ in range(15)]
fidelitybonds = ["bbbb" for _ in range(15)] fidelitybonds = ["bbbb" for _ in range(15)]
d = self.callRemote(JMOffers, d = self.callRemote(JMOffers,
orderbook=json.dumps(orderbook), orderbook=json.dumps(orderbook),
fidelitybonds=json.dumps(fidelitybonds)) fidelitybonds=json.dumps(fidelitybonds))
self.defaultCallbacks(d) self.defaultCallbacks(d)
return {'accepted': True} return {'accepted': True}
@ -217,16 +217,16 @@ class JMTestServerProtocol(JMBaseProtocol):
def on_JM_MAKE_TX(self, nick_list, txhex): def on_JM_MAKE_TX(self, nick_list, txhex):
show_receipt("JMMAKETX", nick_list, txhex) show_receipt("JMMAKETX", nick_list, txhex)
d = self.callRemote(JMSigReceived, d = self.callRemote(JMSigReceived,
nick="dummynick", nick="dummynick",
sig="xxxsig") sig="xxxsig")
self.defaultCallbacks(d) self.defaultCallbacks(d)
#add dummy calls to check message sign and message verify #add dummy calls to check message sign and message verify
d2 = self.callRemote(JMRequestMsgSig, d2 = self.callRemote(JMRequestMsgSig,
nick="dummynickforsign", nick="dummynickforsign",
cmd="command1", cmd="command1",
msg="msgforsign", msg="msgforsign",
msg_to_be_signed="fullmsgforsign", msg_to_be_signed="fullmsgforsign",
hostid="hostid1") hostid="hostid1")
self.defaultCallbacks(d2) self.defaultCallbacks(d2)
#To test, this must include a valid ecdsa sig #To test, this must include a valid ecdsa sig
fullmsg = "fullmsgforverify" fullmsg = "fullmsgforverify"
@ -234,18 +234,18 @@ class JMTestServerProtocol(JMBaseProtocol):
pub = bintohex(bitcoin.privkey_to_pubkey(priv)) pub = bintohex(bitcoin.privkey_to_pubkey(priv))
sig = bitcoin.ecdsa_sign(fullmsg, priv) sig = bitcoin.ecdsa_sign(fullmsg, priv)
d3 = self.callRemote(JMRequestMsgSigVerify, d3 = self.callRemote(JMRequestMsgSigVerify,
msg="msgforverify", msg="msgforverify",
fullmsg=fullmsg, fullmsg=fullmsg,
sig=sig, sig=sig,
pubkey=pub, pubkey=pub,
nick="dummynickforverify", nick="dummynickforverify",
hashlen=4, hashlen=4,
max_encoded=5, max_encoded=5,
hostid="hostid2") hostid="hostid2")
self.defaultCallbacks(d3) self.defaultCallbacks(d3)
d4 = self.callRemote(JMSigReceived, d4 = self.callRemote(JMSigReceived,
nick="dummynick", nick="dummynick",
sig="dummysig") sig="dummysig")
self.defaultCallbacks(d4) self.defaultCallbacks(d4)
return {'accepted': True} return {'accepted': True}

83
jmdaemon/jmdaemon/daemon_protocol.py

@ -100,11 +100,11 @@ class BIP78ReceiverResource(JMHTTPResource):
def __init__(self, info_callback, shutdown_callback, post_request_handler): def __init__(self, info_callback, shutdown_callback, post_request_handler):
""" The POST request handling callback has function signature: """ The POST request handling callback has function signature:
args: (request-body-content-in-bytes,) args: (request-body-content-in-bytes,)
returns: (errormsg, errcode, httpcode, response-in-bytes) returns: (errormsg, errcode, httpcode, response-in-bytes)
If the request was successful, errormsg should be true and response If the request was successful, errormsg should be true and response
should be in bytes, to be sent in the return value of render_POST(). should be in bytes, to be sent in the return value of render_POST().
""" """
self.post_request_handler = post_request_handler self.post_request_handler = post_request_handler
super().__init__(info_callback, shutdown_callback) super().__init__(info_callback, shutdown_callback)
@ -157,6 +157,7 @@ class BIP78ReceiverResource(JMHTTPResource):
self.info_callback("Shutting down, payjoin negotiation failed.") self.info_callback("Shutting down, payjoin negotiation failed.")
self.shutdown_callback() self.shutdown_callback()
class HTTPPassThrough(amp.AMP): class HTTPPassThrough(amp.AMP):
""" This class supports passing through """ This class supports passing through
requests over HTTPS or over a socks proxy to a remote requests over HTTPS or over a socks proxy to a remote
@ -204,9 +205,9 @@ class HTTPPassThrough(amp.AMP):
def getRequest(self, server, success_callback, url=None, headers=None): def getRequest(self, server, success_callback, url=None, headers=None):
""" Make GET request to server server, if response received OK, """ Make GET request to server server, if response received OK,
passed to success_callback, which must have function signature passed to success_callback, which must have function signature
(response, server). (response, server).
""" """
agent, destination_url = self.getAgentDestination(server) agent, destination_url = self.getAgentDestination(server)
if url: if url:
destination_url = destination_url + url destination_url = destination_url + url
@ -228,7 +229,7 @@ class HTTPPassThrough(amp.AMP):
def postRequest(self, body, server, success_callback, def postRequest(self, body, server, success_callback,
url=None, params=None, headers=None): url=None, params=None, headers=None):
""" Pass body of post request as string, will be encoded here. """ Pass body of post request as string, will be encoded here.
""" """
agent, destination_url = self.getAgentDestination(server, agent, destination_url = self.getAgentDestination(server,
params=params) params=params)
if url: if url:
@ -301,25 +302,25 @@ class BIP78ServerProtocol(HTTPPassThrough):
def info_callback(self, msg): def info_callback(self, msg):
""" Informational messages are all passed """ Informational messages are all passed
to the client. TODO makes sense to log locally to the client. TODO makes sense to log locally
too, in case daemon is isolated?. too, in case daemon is isolated?.
""" """
d = self.callRemote(BIP78InfoMsg, infomsg=msg) d = self.callRemote(BIP78InfoMsg, infomsg=msg)
self.defaultCallbacks(d) self.defaultCallbacks(d)
def onion_hostname_callback(self, hostname): def onion_hostname_callback(self, hostname):
""" On successful start of HS, we pass hostname """ On successful start of HS, we pass hostname
to client, who can use this to build the full URI. to client, who can use this to build the full URI.
""" """
d = self.callRemote(BIP78ReceiverUp, d = self.callRemote(BIP78ReceiverUp,
hostname=hostname) hostname=hostname)
self.defaultCallbacks(d) self.defaultCallbacks(d)
def post_request_handler(self, request, body, params): def post_request_handler(self, request, body, params):
""" Fired when a sender has sent a POST request """ Fired when a sender has sent a POST request
to our hidden service. Argument `body` should be a base64 to our hidden service. Argument `body` should be a base64
string and params should be a dict. string and params should be a dict.
""" """
self.post_request = request self.post_request = request
d = self.callRemote(BIP78ReceiverOriginalPSBT, body=body, d = self.callRemote(BIP78ReceiverOriginalPSBT, body=body,
params=bdict_sdict_convert(params)) params=bdict_sdict_convert(params))
@ -381,8 +382,8 @@ class SNICKERDaemonServerProtocol(HTTPPassThrough):
@SNICKERProposerPostProposals.responder @SNICKERProposerPostProposals.responder
def on_SNICKER_PROPOSER_POST_PROPOSALS(self, proposals, server): def on_SNICKER_PROPOSER_POST_PROPOSALS(self, proposals, server):
""" Receives a list of proposals to be posted to a specific """ Receives a list of proposals to be posted to a specific
server. server.
""" """
self.postRequest(proposals, server, self.receive_proposals_response) self.postRequest(proposals, server, self.receive_proposals_response)
return {"accepted": True} return {"accepted": True}
@ -418,7 +419,7 @@ class SNICKERDaemonServerProtocol(HTTPPassThrough):
def receive_proposals_from_server(self, response, server): def receive_proposals_from_server(self, response, server):
""" Parses the response from one server. """ Parses the response from one server.
""" """
# if the response code is not 200 OK, we must let the client # if the response code is not 200 OK, we must let the client
# know that this server is not responding as expected. # know that this server is not responding as expected.
if int(response.code) != 200: if int(response.code) != 200:
@ -484,7 +485,7 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch):
def defaultErrback(self, failure): def defaultErrback(self, failure):
"""TODO better network error handling. """TODO better network error handling.
""" """
failure.trap(ConnectionAborted, ConnectionClosed, failure.trap(ConnectionAborted, ConnectionClosed,
ConnectionDone, ConnectionLost) ConnectionDone, ConnectionLost)
@ -630,8 +631,8 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch):
@JMMakeTx.responder @JMMakeTx.responder
def on_JM_MAKE_TX(self, nick_list, txhex): def on_JM_MAKE_TX(self, nick_list, txhex):
"""Taker sends the prepared unsigned transaction """Taker sends the prepared unsigned transaction
to all the Makers in nick_list to all the Makers in nick_list
""" """
if not self.jm_state == 4: if not self.jm_state == 4:
log.msg("Make tx was called in wrong state, rejecting") log.msg("Make tx was called in wrong state, rejecting")
return {'accepted': False} return {'accepted': False}
@ -649,9 +650,9 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch):
@JMAnnounceOffers.responder @JMAnnounceOffers.responder
def on_JM_ANNOUNCE_OFFERS(self, to_announce, to_cancel, offerlist): def on_JM_ANNOUNCE_OFFERS(self, to_announce, to_cancel, offerlist):
"""Called by Maker to reset his current offerlist; """Called by Maker to reset his current offerlist;
Daemon decides what messages (cancel, announce) to Daemon decides what messages (cancel, announce) to
send to the message channel. send to the message channel.
""" """
if self.role != "MAKER": if self.role != "MAKER":
return return
self.offerlist = offerlist self.offerlist = offerlist
@ -670,9 +671,9 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch):
@JMIOAuth.responder @JMIOAuth.responder
def on_JM_IOAUTH(self, nick, utxolist, pubkey, cjaddr, changeaddr, pubkeysig): def on_JM_IOAUTH(self, nick, utxolist, pubkey, cjaddr, changeaddr, pubkeysig):
"""Daemon constructs full !ioauth message to be sent on message """Daemon constructs full !ioauth message to be sent on message
channel based on data from Maker. Relevant data (utxos, addresses) channel based on data from Maker. Relevant data (utxos, addresses)
are stored in the active_orders dict keyed by the nick of the Taker. are stored in the active_orders dict keyed by the nick of the Taker.
""" """
if not self.role == "MAKER": if not self.role == "MAKER":
return return
if nick not in self.active_orders: if nick not in self.active_orders:
@ -791,7 +792,7 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch):
""" """
if nick not in self.active_orders: if nick not in self.active_orders:
return return
ao =self.active_orders[nick] ao = self.active_orders[nick]
#ask the client to validate the commitment and prepare the utxo data #ask the client to validate the commitment and prepare the utxo data
d = self.callRemote(JMAuthReceived, d = self.callRemote(JMAuthReceived,
nick=nick, nick=nick,
@ -805,8 +806,8 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch):
@maker_only @maker_only
def on_commitment_seen(self, nick, commitment): def on_commitment_seen(self, nick, commitment):
"""Triggered when we see a commitment for blacklisting """Triggered when we see a commitment for blacklisting
appear in the public pit channel. appear in the public pit channel.
""" """
#just add if necessary, ignore return value. #just add if necessary, ignore return value.
check_utxo_blacklist(commitment, persist=True) check_utxo_blacklist(commitment, persist=True)
log.msg("Received commitment broadcast by other maker: " + str( log.msg("Received commitment broadcast by other maker: " + str(
@ -815,10 +816,10 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch):
@maker_only @maker_only
def on_commitment_transferred(self, nick, commitment): def on_commitment_transferred(self, nick, commitment):
"""Triggered when a privmsg is received from another maker """Triggered when a privmsg is received from another maker
with a commitment to announce in public (obfuscation of source). with a commitment to announce in public (obfuscation of source).
We simply post it in public (not affected by whether we ourselves We simply post it in public (not affected by whether we ourselves
are *accepting* commitment broadcasts. are *accepting* commitment broadcasts.
""" """
self.mcc.pubmsg("!hp2 " + commitment) self.mcc.pubmsg("!hp2 " + commitment)
@maker_only @maker_only
@ -831,8 +832,8 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch):
@maker_only @maker_only
def on_seen_tx(self, nick, tx): def on_seen_tx(self, nick, tx):
"""Passes the txhex to the Maker for verification """Passes the txhex to the Maker for verification
and signing. Note the security checks occur in Maker. and signing. Note the security checks occur in Maker.
""" """
if nick not in self.active_orders: if nick not in self.active_orders:
return return
#we send a copy of the entire "active_orders" entry except the cryptobox, #we send a copy of the entire "active_orders" entry except the cryptobox,
@ -900,11 +901,11 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch):
""" """
with self.sig_lock: with self.sig_lock:
d = self.callRemote(JMRequestMsgSig, d = self.callRemote(JMRequestMsgSig,
nick=str(nick), nick=str(nick),
cmd=str(cmd), cmd=str(cmd),
msg=str(msg), msg=str(msg),
msg_to_be_signed=str(msg_to_be_signed), msg_to_be_signed=str(msg_to_be_signed),
hostid=str(hostid)) hostid=str(hostid))
self.defaultCallbacks(d) self.defaultCallbacks(d)
def request_signature_verify(self, msg, fullmsg, sig, pubkey, nick, hashlen, def request_signature_verify(self, msg, fullmsg, sig, pubkey, nick, hashlen,
@ -939,8 +940,8 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch):
def transfer_commitment(self, commit): def transfer_commitment(self, commit):
"""Send this commitment via privmsg to one (random) """Send this commitment via privmsg to one (random)
other maker. other maker.
""" """
crow = self.db.execute( crow = self.db.execute(
'SELECT DISTINCT counterparty FROM orderbook ORDER BY ' + 'SELECT DISTINCT counterparty FROM orderbook ORDER BY ' +
'RANDOM() LIMIT 1;' 'RANDOM() LIMIT 1;'

36
jmdaemon/test/test_daemon_protocol.py

@ -101,7 +101,7 @@ class JMTestClientProtocol(JMBaseProtocol):
show_receipt("JMFILLRESPONSE", success, ioauth_data) show_receipt("JMFILLRESPONSE", success, ioauth_data)
reactor.callLater(1, self.maketx, ioauth_data) reactor.callLater(1, self.maketx, ioauth_data)
return {'accepted': True} return {'accepted': True}
def maketx(self, ioauth_data): def maketx(self, ioauth_data):
nl = list(ioauth_data) nl = list(ioauth_data)
d = self.callRemote(JMMakeTx, d = self.callRemote(JMMakeTx,
@ -118,18 +118,18 @@ class JMTestClientProtocol(JMBaseProtocol):
nick = str(list(t_chosen_orders.keys())[0]) nick = str(list(t_chosen_orders.keys())[0])
b64tx = base64.b64encode(b"deadbeef").decode('ascii') b64tx = base64.b64encode(b"deadbeef").decode('ascii')
d1 = self.callRemote(JMMsgSignatureVerify, d1 = self.callRemote(JMMsgSignatureVerify,
verif_result=True, verif_result=True,
nick=nick, nick=nick,
fullmsg="!push " + b64tx + " abc def", fullmsg="!push " + b64tx + " abc def",
hostid="dummy") hostid="dummy")
self.defaultCallbacks(d1) self.defaultCallbacks(d1)
#unverified #unverified
d2 = self.callRemote(JMMsgSignatureVerify, d2 = self.callRemote(JMMsgSignatureVerify,
verif_result=False, verif_result=False,
nick=nick, nick=nick,
fullmsg="!push " + b64tx + " abc def", fullmsg="!push " + b64tx + " abc def",
hostid="dummy") hostid="dummy")
self.defaultCallbacks(d2) self.defaultCallbacks(d2)
d = self.callRemote(JMFill, d = self.callRemote(JMFill,
amount=100, amount=100,
commitment="dummycommitment", commitment="dummycommitment",
@ -173,7 +173,7 @@ class JMTestClientProtocol(JMBaseProtocol):
class JMTestClientProtocolFactory(protocol.ClientFactory): class JMTestClientProtocolFactory(protocol.ClientFactory):
protocol = JMTestClientProtocol protocol = JMTestClientProtocol
def show_receipt(name, *args): def show_receipt(name, *args):
tmsg("Received msgtype: " + name + ", args: " + ",".join([str(x) for x in args])) tmsg("Received msgtype: " + name + ", args: " + ",".join([str(x) for x in args]))
@ -209,7 +209,7 @@ class JMDaemonTestServerProtocol(JMDaemonServerProtocol):
o["minsize"], o["maxsize"], o["minsize"], o["maxsize"],
o["txfee"], o["cjfee"]) o["txfee"], o["cjfee"])
return super().on_JM_REQUEST_OFFERS() return super().on_JM_REQUEST_OFFERS()
@JMInit.responder @JMInit.responder
def on_JM_INIT(self, bcsource, network, irc_configs, minmakers, def on_JM_INIT(self, bcsource, network, irc_configs, minmakers,
maker_timeout_sec, dust_threshold): maker_timeout_sec, dust_threshold):
@ -226,14 +226,14 @@ class JMDaemonTestServerProtocol(JMDaemonServerProtocol):
OrderbookWatch.set_msgchan(self, self.mcc) OrderbookWatch.set_msgchan(self, self.mcc)
#register taker-specific msgchan callbacks here #register taker-specific msgchan callbacks here
self.mcc.register_taker_callbacks(self.on_error, self.on_pubkey, self.mcc.register_taker_callbacks(self.on_error, self.on_pubkey,
self.on_ioauth, self.on_sig) self.on_ioauth, self.on_sig)
self.mcc.set_daemon(self) self.mcc.set_daemon(self)
self.restart_mc_required = True self.restart_mc_required = True
d = self.callRemote(JMInitProto, d = self.callRemote(JMInitProto,
nick_hash_length=NICK_HASH_LENGTH, nick_hash_length=NICK_HASH_LENGTH,
nick_max_encoded=NICK_MAX_ENCODED, nick_max_encoded=NICK_MAX_ENCODED,
joinmarket_nick_header=JOINMARKET_NICK_HEADER, joinmarket_nick_header=JOINMARKET_NICK_HEADER,
joinmarket_version=JM_VERSION) joinmarket_version=JM_VERSION)
self.defaultCallbacks(d) self.defaultCallbacks(d)
return {'accepted': True} return {'accepted': True}
@ -267,7 +267,7 @@ class JMDaemonTestServerProtocol(JMDaemonServerProtocol):
class JMDaemonTestServerProtocolFactory(ServerFactory): class JMDaemonTestServerProtocolFactory(ServerFactory):
protocol = JMDaemonTestServerProtocol protocol = JMDaemonTestServerProtocol
def buildProtocol(self, addr): def buildProtocol(self, addr):
return JMDaemonTestServerProtocol(self) return JMDaemonTestServerProtocol(self)

Loading…
Cancel
Save