(Steve Dougherty)
2013-07-22: Add initial fn-connect implementation. Add initial fn-connect implementation. Only pings, does not handle session conflicts, and does not respond to any commands because none are currently implemented on the plugin side either.
diff --git a/infocalypse/__init__.py b/infocalypse/__init__.py --- a/infocalypse/__init__.py +++ b/infocalypse/__init__.py @@ -379,6 +379,8 @@ PULL_OPTS = [('', 'hash', [], 'repo hash + 'known users')] cmdtable = { + "fn-connect": (infocalypse_connect, FCP_OPTS), + "fn-pull": (infocalypse_pull, [('', 'uri', '', 'request URI to pull from')] + PULL_OPTS diff --git a/infocalypse/commands.py b/infocalypse/commands.py --- a/infocalypse/commands.py +++ b/infocalypse/commands.py @@ -233,6 +233,11 @@ def infocalypse_check_notifications(ui, wot.check_notifications(ui, opts['wot']) +def infocalypse_connect(ui, repo, **opts): + import wot + wot.connect(ui, repo) + + def infocalypse_push(ui_, repo, **opts): """ Push to an Infocalypse repository in Freenet. """ params, stored_cfg = get_config_info(ui_, opts) diff --git a/infocalypse/wot.py b/infocalypse/wot.py --- a/infocalypse/wot.py +++ b/infocalypse/wot.py @@ -1,4 +1,5 @@ import string +from time import sleep import fcp from mercurial import util from config import Config @@ -11,10 +12,42 @@ from keys import USK import yaml from email.mime.text import MIMEText import imaplib +import threading FREEMAIL_SMTP_PORT = 4025 FREEMAIL_IMAP_PORT = 4143 VCS_PREFIX = "[vcs] " +PLUGIN_NAME = "org.freenetproject.plugin.infocalypse_webui.main.InfocalypsePlugin" + + +def connect(ui, repo): + node = fcp.FCPNode() + + # TODO: Should I be using this? Looks internal. The identifier needs to + # be consistent though. + fcp_id = node._getUniqueId() + + ui.status("Connecting as '%s'.\n" % fcp_id) + + def ping(): + pong = node.fcpPluginMessage(plugin_name=PLUGIN_NAME, id=fcp_id, + plugin_params={'Message': 'Ping'}) + # TODO: Quit on session conflict. + # Must be faster than the timeout threshold. (5 seconds) + threading.Timer(4.0, ping).start() + + # Start self-perpetuating pinging in the background. + t = threading.Timer(0.0, ping) + # Daemon threads do not hold up the process exiting. Allows prompt + # response to - for instance - SIGTERM. + t.daemon = True + t.start() + + while True: + command = node.fcpPluginMessage(plugin_name=PLUGIN_NAME, id=fcp_id, + plugin_params={'Message': + 'ClearToSend'}) + # TODO: Dispatch commands; quit on session conflict. def send_pull_request(ui, repo, from_identifier, to_identifier, to_repo_name):