From f075f0bb5f9a57cacf4c398d3f01de61016f631d Mon Sep 17 00:00:00 2001 From: TheLazieR Yip Date: Tue, 22 Nov 2016 20:02:20 -0500 Subject: [PATCH] Add coin's IRC parameters --- lib/coins.py | 8 ++++++++ server/irc.py | 23 ++++++++++++++--------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/coins.py b/lib/coins.py index 4e56894..71129b6 100644 --- a/lib/coins.py +++ b/lib/coins.py @@ -39,6 +39,11 @@ class Coin(object): VALUE_PER_COIN = 100000000 CHUNK_SIZE=2016 STRANGE_VERBYTE = 0xff + # IRC Defaults + IRC_PREFIX = "E_" + IRC_CHANNEL = "#electrum" + IRC_SERVER = "irc.freenode.net" + IRC_PORT = 6667 @classmethod def lookup_coin_class(cls, name, net): @@ -359,6 +364,8 @@ class Dash(Coin): TX_COUNT = 2157510 TX_PER_BLOCK = 4 DEFAULT_RPC_PORT = 9998 + IRC_PREFIX = "D_" + IRC_CHANNEL = "#electrum-dash" @classmethod def header_hashes(cls, header): @@ -381,3 +388,4 @@ class DashTestnet(Dash): TX_COUNT = 132681 TX_PER_BLOCK = 1 DEFAULT_RPC_PORT = 19998 + IRC_PREFIX = "d_" diff --git a/server/irc.py b/server/irc.py index 3a938cd..5ee50ea 100644 --- a/server/irc.py +++ b/server/irc.py @@ -30,7 +30,6 @@ def port_text(letter, port, default): class IRC(LoggedClass): - PEER_REGEXP = re.compile('(E_[^!]*)!') Peer = namedtuple('Peer', 'ip_addr host ports') class DisconnectedError(Exception): @@ -45,9 +44,15 @@ class IRC(LoggedClass): version = '1.0' self.real_name = '{} v{} {} {}'.format(env.report_host, version, tcp_text, ssl_text) - self.nick = 'E_{}'.format(env.irc_nick if env.irc_nick else + self.prefix = env.coin.IRC_PREFIX + self.nick = '{}{}'.format(self.prefix, + env.irc_nick if env.irc_nick else double_sha256(env.report_host.encode()) [:5].hex()) + self.channel = env.coin.IRC_CHANNEL + self.irc_server = env.coin.IRC_SERVER + self.irc_port = env.coin.IRC_PORT + self.peer_regexp = re.compile('({}[^!]*)!'.format(self.prefix)) self.peers = {} async def start(self): @@ -72,7 +77,7 @@ class IRC(LoggedClass): while True: try: connection = reactor.server() - connection.connect('irc.freenode.net', 6667, + connection.connect(self.irc_server, self.irc_port, self.nick, ircname=self.real_name) connection.set_keepalive(60) while True: @@ -89,8 +94,8 @@ class IRC(LoggedClass): .format(event.type, event.source, event.arguments)) def on_welcome(self, connection, event): - '''Called when we connect to freenode.''' - connection.join('#electrum') + '''Called when we connect to irc server.''' + connection.join(self.channel) def on_disconnect(self, connection, event): '''Called if we are disconnected.''' @@ -99,20 +104,20 @@ class IRC(LoggedClass): def on_join(self, connection, event): '''Called when someone new connects to our channel, including us.''' - match = self.PEER_REGEXP.match(event.source) + match = self.peer_regexp.match(event.source) if match: connection.who(match.group(1)) def on_quit(self, connection, event): '''Called when someone leaves our channel.''' - match = self.PEER_REGEXP.match(event.source) + match = self.peer_regexp.match(event.source) if match: self.peers.pop(match.group(1), None) def on_kick(self, connection, event): '''Called when someone is kicked from our channel.''' self.log_event(event) - match = self.PEER_REGEXP.match(event.arguments[0]) + match = self.peer_regexp.match(event.arguments[0]) if match: self.peers.pop(match.group(1), None) @@ -123,7 +128,7 @@ class IRC(LoggedClass): The users are space-separated in the 2nd argument. ''' for peer in event.arguments[2].split(): - if peer.startswith("E_"): + if peer.startswith(self.prefix): connection.who(peer) def on_whoreply(self, connection, event):