Browse Source

control callback access in daemon

master
Adam Gibson 9 years ago
parent
commit
c54d4f050e
No known key found for this signature in database
GPG Key ID: B3AE09F1E9A3197A
  1. 62
      jmdaemon/jmdaemon/daemon_protocol.py

62
jmdaemon/jmdaemon/daemon_protocol.py

@ -23,6 +23,40 @@ import time
import threading import threading
import os import os
import copy import copy
from functools import wraps
"""Joinmarket application protocol control flow.
For documentation on protocol (formats, message sequence) see
https://github.com/JoinMarket-Org/JoinMarket-Docs/blob/master/
Joinmarket-messaging-protocol.md
"""
"""
***
API
***
The client-daemon two-way communication is documented in jmbase.commands.py
"""
"""Decorators for limiting which
inbound callbacks trigger in the DaemonProtocol
object.
"""
def maker_only(func):
@wraps(func)
def func_wrapper(inst, *args, **kwargs):
if inst.role == "MAKER":
return func(inst, *args, **kwargs)
return None
return func_wrapper
def taker_only(func):
@wraps(func)
def func_wrapper(inst, *args, **kwargs):
if inst.role == "TAKER":
return func(inst, *args, **kwargs)
return None
return func_wrapper
def check_utxo_blacklist(commitment, persist=False): def check_utxo_blacklist(commitment, persist=False):
"""Compare a given commitment with the persisted blacklist log file, """Compare a given commitment with the persisted blacklist log file,
@ -51,19 +85,6 @@ def check_utxo_blacklist(commitment, persist=False):
#usage). #usage).
return True return True
"""Joinmarket application protocol control flow.
For documentation on protocol (formats, message sequence) see
https://github.com/JoinMarket-Org/JoinMarket-Docs/blob/master/
Joinmarket-messaging-protocol.md
"""
"""
***
API
***
The client-daemon two-way communication is documented in jmbase.commands.py
"""
class JMProtocolError(Exception): class JMProtocolError(Exception):
pass pass
@ -297,15 +318,16 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch):
d = self.callRemote(JMUp) d = self.callRemote(JMUp)
self.defaultCallbacks(d) self.defaultCallbacks(d)
@maker_only
def on_orderbook_requested(self, nick, mc=None): def on_orderbook_requested(self, nick, mc=None):
"""Dealt with by daemon, assuming offerlist is up to date """Dealt with by daemon, assuming offerlist is up to date
""" """
self.mcc.announce_orders(self.offerlist, nick, mc) self.mcc.announce_orders(self.offerlist, nick, mc)
@maker_only
def on_order_fill(self, nick, oid, amount, taker_pk, commit): def on_order_fill(self, nick, oid, amount, taker_pk, commit):
"""Handled locally in daemon. """Handled locally in daemon.
""" """
if self.role != "MAKER": return
if nick in self.active_orders: if nick in self.active_orders:
log.msg("Restarting transaction for nick: " + nick) log.msg("Restarting transaction for nick: " + nick)
if not commit[0] in COMMITMENT_PREFIXES: if not commit[0] in COMMITMENT_PREFIXES:
@ -342,9 +364,8 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch):
"commit": scommit} "commit": scommit}
self.mcc.prepare_privmsg(nick, "pubkey", kp.hex_pk()) self.mcc.prepare_privmsg(nick, "pubkey", kp.hex_pk())
@maker_only
def on_seen_auth(self, nick, commitment_revelation): def on_seen_auth(self, nick, commitment_revelation):
if not self.role == "MAKER":
return
if not nick in self.active_orders: if not nick in self.active_orders:
return return
ao =self.active_orders[nick] ao =self.active_orders[nick]
@ -358,6 +379,7 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch):
kphex=ao["kp"].hex_pk()) kphex=ao["kp"].hex_pk())
self.defaultCallbacks(d) self.defaultCallbacks(d)
@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. If the policy is set, appear in the public pit channel. If the policy is set,
@ -377,6 +399,7 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch):
log.msg("Received commitment broadcast by other maker: " + str( log.msg("Received commitment broadcast by other maker: " + str(
commitment) + ", ignored.") commitment) + ", ignored.")
@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).
@ -385,12 +408,12 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch):
""" """
self.mcc.pubmsg("!hp2 " + commitment) self.mcc.pubmsg("!hp2 " + commitment)
@maker_only
def on_push_tx(self, nick, txhex): def on_push_tx(self, nick, txhex):
log.msg('received pushtx message, ignoring, TODO') log.msg('received pushtx message, ignoring, TODO')
@maker_only
def on_seen_tx(self, nick, txhex): def on_seen_tx(self, nick, txhex):
if self.role != "MAKER":
return
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,
@ -404,6 +427,7 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch):
offer=json.dumps(ao)) offer=json.dumps(ao))
self.defaultCallbacks(d) self.defaultCallbacks(d)
@taker_only
def on_pubkey(self, nick, maker_pk): def on_pubkey(self, nick, maker_pk):
"""This is handled locally in the daemon; set up e2e """This is handled locally in the daemon; set up e2e
encrypted messaging with this counterparty encrypted messaging with this counterparty
@ -420,6 +444,7 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch):
return return
self.mcc.prepare_privmsg(nick, "auth", str(self.revelation)) self.mcc.prepare_privmsg(nick, "auth", str(self.revelation))
@taker_only
def on_ioauth(self, nick, utxo_list, auth_pub, cj_addr, change_addr, def on_ioauth(self, nick, utxo_list, auth_pub, cj_addr, change_addr,
btc_sig): btc_sig):
"""Passes through to Taker the information from counterparties once """Passes through to Taker the information from counterparties once
@ -435,6 +460,7 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch):
#Finish early if we got all #Finish early if we got all
self.respondToIoauths(True) self.respondToIoauths(True)
@taker_only
def on_sig(self, nick, sig): def on_sig(self, nick, sig):
"""Pass signature through to Taker. """Pass signature through to Taker.
""" """

Loading…
Cancel
Save