From zothar at freenetproject.org Sun Jul 1 14:39:46 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Sun, 1 Jul 2007 14:39:46 +0000 (UTC) Subject: [Pyfreenet] r13861 - trunk/apps/pyFreenet/fcp Message-ID: <20070701143946.73A7D4790AC@emu.freenetproject.org> Author: zothar Date: 2007-07-01 14:39:46 +0000 (Sun, 01 Jul 2007) New Revision: 13861 Modified: trunk/apps/pyFreenet/fcp/node.py Log: pyFreenet: don't bomb on a missing field, because we may not have to Modified: trunk/apps/pyFreenet/fcp/node.py =================================================================== --- trunk/apps/pyFreenet/fcp/node.py 2007-07-01 11:43:04 UTC (rev 13860) +++ trunk/apps/pyFreenet/fcp/node.py 2007-07-01 14:39:46 UTC (rev 13861) @@ -1921,7 +1921,10 @@ # handle ClientGet responses if hdr == 'DataFound': - log(INFO, "Got DataFound for URI=%s" % job.kw['URI']) + if( job.kw.has_key( 'URI' )): + log(INFO, "Got DataFound for URI=%s" % job.kw['URI']) + else: + log(ERROR, "Got DataFound without URI") mimetype = msg['Metadata.ContentType'] if job.kw.has_key('Filename'): # already stored to disk, done From zothar at freenetproject.org Sun Jul 1 14:43:00 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Sun, 1 Jul 2007 14:43:00 +0000 (UTC) Subject: [Pyfreenet] r13862 - trunk/apps/pyFreenet/fcp Message-ID: <20070701144300.C3B814798DF@emu.freenetproject.org> Author: zothar Date: 2007-07-01 14:43:00 +0000 (Sun, 01 Jul 2007) New Revision: 13862 Modified: trunk/apps/pyFreenet/fcp/node.py Log: pyFreenet: redirect on TOO_MANY_PATH_COMPONENTS Modified: trunk/apps/pyFreenet/fcp/node.py =================================================================== --- trunk/apps/pyFreenet/fcp/node.py 2007-07-01 14:39:46 UTC (rev 13861) +++ trunk/apps/pyFreenet/fcp/node.py 2007-07-01 14:43:00 UTC (rev 13862) @@ -1979,6 +1979,13 @@ self._txMsg(job.cmd, **job.kw) log(DETAIL, "Redirect to %s" % uri) return + # see if it's just a TOO_MANY_PATH_COMPONENTS problem + if msg.get('ShortCodeDescription', None) == "Too many path components": + uri = msg['RedirectURI'] + job.kw['URI'] = uri + self._txMsg(job.cmd, **job.kw) + log(DETAIL, "Redirect to %s" % uri) + return # return an exception job.callback("failed", msg) From zothar at freenetproject.org Sun Jul 1 14:55:44 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Sun, 1 Jul 2007 14:55:44 +0000 (UTC) Subject: [Pyfreenet] r13863 - trunk/apps/pyFreenet/fcp Message-ID: <20070701145544.018CB47A211@emu.freenetproject.org> Author: zothar Date: 2007-07-01 14:55:43 +0000 (Sun, 01 Jul 2007) New Revision: 13863 Modified: trunk/apps/pyFreenet/fcp/node.py Log: pyFreenet: make following redirects optional Modified: trunk/apps/pyFreenet/fcp/node.py =================================================================== --- trunk/apps/pyFreenet/fcp/node.py 2007-07-01 14:43:00 UTC (rev 13862) +++ trunk/apps/pyFreenet/fcp/node.py 2007-07-01 14:55:43 UTC (rev 13863) @@ -359,6 +359,7 @@ - ignoreds - don't check local datastore - file - if given, this is a pathname to which to store the retrieved key + - followRedirect - follow a redirect if true, otherwise fail the get - nodata - if true, no data will be returned. This can be a useful test of whether a key is retrievable, without having to consume resources by retrieving it @@ -1796,6 +1797,7 @@ Status is one of 'successful', 'pending' or 'failed'. value is the primitive return value if successful, or the raw node message if pending or failed + - followRedirect - follow a redirect if true, otherwise fail the get - rawcmd - a raw command buffer to send directly - options specific to command such as 'URI' - timeout - timeout in seconds for job completion, default 1 year @@ -1817,6 +1819,7 @@ log(DEBUG, "_submitCmd: kw=%s" % kw) async = kw.pop('async', False) + followRedirect = kw.pop('followRedirect', True) stream = kw.pop('stream', None) waituntilsent = kw.pop('waituntilsent', False) keepjob = kw.pop('keep', False) @@ -1832,6 +1835,8 @@ stream=stream) log(DEBUG, "_submitCmd: timeout=%s" % timeout) + + job.followRedirect = followRedirect if cmd == 'ClientGet': job.uri = kw['URI'] @@ -1973,14 +1978,14 @@ if hdr == 'GetFailed': # see if it's just a redirect problem - if msg.get('ShortCodeDescription', None) == "New URI": + if job.followRedirect and msg.get('ShortCodeDescription', None) == "New URI": uri = msg['RedirectURI'] job.kw['URI'] = uri self._txMsg(job.cmd, **job.kw) log(DETAIL, "Redirect to %s" % uri) return - # see if it's just a TOO_MANY_PATH_COMPONENTS problem - if msg.get('ShortCodeDescription', None) == "Too many path components": + # see if it's just a TOO_MANY_PATH_COMPONENTS redirect + if job.followRedirect and msg.get('ShortCodeDescription', None) == "Too many path components": uri = msg['RedirectURI'] job.kw['URI'] = uri self._txMsg(job.cmd, **job.kw) From zothar at freenetproject.org Sun Jul 1 19:58:22 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Sun, 1 Jul 2007 19:58:22 +0000 (UTC) Subject: [Pyfreenet] r13864 - trunk/apps/pyFreenet/fcp Message-ID: <20070701195822.026DE47A20A@emu.freenetproject.org> Author: zothar Date: 2007-07-01 19:58:21 +0000 (Sun, 01 Jul 2007) New Revision: 13864 Modified: trunk/apps/pyFreenet/fcp/node.py Log: pyFreenet: implement TestDDA as testDDA() (bug #1296) Modified: trunk/apps/pyFreenet/fcp/node.py =================================================================== --- trunk/apps/pyFreenet/fcp/node.py 2007-07-01 14:55:43 UTC (rev 13863) +++ trunk/apps/pyFreenet/fcp/node.py 2007-07-01 19:58:21 UTC (rev 13864) @@ -18,9 +18,20 @@ #@+others #@+node:imports -import sys, os, socket, time, thread, pprint -import threading, mimetypes, sha, Queue -import select, traceback, base64 +import Queue +import base64 +import mimetypes +import os +import pprint +import select +import sha +import socket +import stat +import sys +import thread +import threading +import time +import traceback #@-node:imports #@+node:exceptions @@ -1180,6 +1191,56 @@ return self._submitCmd("__global", "GetNode", **kw) #@-node:refstats + #@+node:testDDA + def testDDA(self, **kw): + """ + Test for Direct Disk Access capability on a directory (can the node and the FCP client both access the same directory?) + + Keywords: + - async - whether to do this call asynchronously, and + return a JobTicket object + - callback - if given, this should be a callable which accepts 2 + arguments: + - status - will be one of 'successful', 'failed' or 'pending' + - value - depends on status: + - if status is 'successful', this will contain the value + returned from the command + - if status is 'failed' or 'pending', this will contain + a dict containing the response from node + - Directory - directory to test + - WithReadDirectory - default False - if True, want node to read from directory for a put operation + - WithWriteDirectory - default False - if True, want node to write to directory for a get operation + """ + + requestResult = self._submitCmd("__global", "TestDDARequest", **kw) + writeFilename = None; + kw = {}; + kw[ 'Directory' ] = requestResult[ 'Directory' ]; + if( requestResult.has_key( 'ReadFilename' )): + readFilename = requestResult[ 'ReadFilename' ]; + readFile = open( readFilename, 'rb' ); + readFileContents = readFile.read(); + readFile.close(); + kw[ 'ReadFilename' ] = readFilename; + kw[ 'ReadContent' ] = readFileContents; + if( requestResult.has_key( 'WriteFilename' ) and requestResult.has_key( 'ContentToWrite' )): + writeFilename = requestResult[ 'WriteFilename' ]; + contentToWrite = requestResult[ 'ContentToWrite' ]; + writeFile = open( writeFilename, 'w+b' ); + writeFileContents = writeFile.write( contentToWrite ); + writeFile.close(); + writeFileStatObject = os.stat( writeFilename ); + writeFileMode = writeFileStatObject.st_mode; + os.chmod( writeFilename, writeFileMode | stat.S_IREAD | stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH ); + responseResult = self._submitCmd("__global", "TestDDAResponse", **kw) + if( None != writeFilename ): + try: + os.remove( writeFilename ); + except OSError, msg: + pass; + return responseResult; + + #@-node:testDDA #@+node:addpeer def addpeer(self, **kw): """ @@ -2131,6 +2192,27 @@ return # ----------------------------- + # handle testDDA messages + + if hdr == 'TestDDAReply': + # return all the data recieved + job.callback('successful', msg) + job._putResult(msg) + + # remove job from queue + self.jobs.pop(id, None) + return + + if hdr == 'TestDDAComplete': + # return all the data recieved + job.callback('successful', msg) + job._putResult(msg) + + # remove job from queue + self.jobs.pop(id, None) + return + + # ----------------------------- # handle NodeData if hdr == 'NodeData': # return all the data recieved From zothar at freenetproject.org Sun Jul 15 16:03:55 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Sun, 15 Jul 2007 16:03:55 +0000 (UTC) Subject: [Pyfreenet] r14137 - trunk/apps/pyFreenet/fcp Message-ID: <20070715160355.2DCA847A248@freenetproject.org> Author: zothar Date: 2007-07-15 16:03:54 +0000 (Sun, 15 Jul 2007) New Revision: 14137 Modified: trunk/apps/pyFreenet/fcp/node.py Log: pyFreenet: added GiveOpennetRef to documention for fcp/node.refstats() Modified: trunk/apps/pyFreenet/fcp/node.py =================================================================== --- trunk/apps/pyFreenet/fcp/node.py 2007-07-15 16:00:38 UTC (rev 14136) +++ trunk/apps/pyFreenet/fcp/node.py 2007-07-15 16:03:54 UTC (rev 14137) @@ -1184,6 +1184,7 @@ returned from the command - if status is 'failed' or 'pending', this will contain a dict containing the response from node + - GiveOpennetRef - default False - if True, return the node's Opennet reference rather than the node's Darknet reference - WithPrivate - default False - if True, includes the node's private node reference fields - WithVolatile - default False - if True, returns a node's volatile info """ From zothar at freenetproject.org Sun Jul 15 16:21:38 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Sun, 15 Jul 2007 16:21:38 +0000 (UTC) Subject: [Pyfreenet] r14138 - trunk/apps/pyFreenet Message-ID: <20070715162138.904E947A11C@freenetproject.org> Author: zothar Date: 2007-07-15 16:21:38 +0000 (Sun, 15 Jul 2007) New Revision: 14138 Modified: trunk/apps/pyFreenet/updater.py Log: pyFreenet: updater.py now fetches a file if it's available remotely if it doesn't exist locally, regardless of versions. Modified: trunk/apps/pyFreenet/updater.py =================================================================== --- trunk/apps/pyFreenet/updater.py 2007-07-15 16:03:54 UTC (rev 14137) +++ trunk/apps/pyFreenet/updater.py 2007-07-15 16:21:38 UTC (rev 14138) @@ -75,6 +75,8 @@ if( remote_versions.has_key( filename )): if( local_versions[ filename ] < remote_versions[ filename ] ): return True; + if( not os.path.exists( filename )): + return True; return False; def process_raw_remote_versions_data( remote_versions, input_lines, filename_prefix ): From zothar at freenetproject.org Sun Jul 15 16:24:16 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Sun, 15 Jul 2007 16:24:16 +0000 (UTC) Subject: [Pyfreenet] r14139 - trunk/apps/pyFreenet Message-ID: <20070715162416.1E89047A203@freenetproject.org> Author: zothar Date: 2007-07-15 16:24:15 +0000 (Sun, 15 Jul 2007) New Revision: 14139 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: if the bogon IPs file is missing, exit after asking the user to run updater.py Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2007-07-15 16:21:38 UTC (rev 14138) +++ trunk/apps/pyFreenet/refbot.py 2007-07-15 16:24:15 UTC (rev 14139) @@ -100,6 +100,13 @@ log("*** This release of the refbot is more than two weeks old. Please run updater.py and try again."); log("***"); my_exit( 1 ); + + # check that we've got a bogon IPs file + if( not os.path.exists( FreenetNodeRefBot.bogon_filename )): + log("***"); + log("*** The bogon IPs file \"%s\" is missing. Please run updater.py and try again." % ( FreenetNodeRefBot.bogon_filename )); + log("***"); + my_exit( 1 ); # check that we've got an updated fcp/node.py try: From zothar at freenetproject.org Sun Jul 15 16:50:35 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Sun, 15 Jul 2007 16:50:35 +0000 (UTC) Subject: [Pyfreenet] r14140 - trunk/apps/pyFreenet Message-ID: <20070715165035.921C5479850@freenetproject.org> Author: zothar Date: 2007-07-15 16:50:35 +0000 (Sun, 15 Jul 2007) New Revision: 14140 Modified: trunk/apps/pyFreenet/updater.py Log: pyFreenet: updater.py now updates all pyFreenet files rather than just the refbot related ones. Also fix a bug that didn't show up until trying to update more than one file in a single subdirectory. Modified: trunk/apps/pyFreenet/updater.py =================================================================== --- trunk/apps/pyFreenet/updater.py 2007-07-15 16:24:15 UTC (rev 14139) +++ trunk/apps/pyFreenet/updater.py 2007-07-15 16:50:35 UTC (rev 14140) @@ -33,10 +33,81 @@ download_base_url = "http://emu.freenetproject.org/cgi-bin/viewcvs.cgi/*checkout*/trunk/apps/pyFreenet/"; # updater.py should be left out of files_to_update files_to_update = [ + "fcp/__init__.py", + "fcp/fproxyproxy.py", + "fcp/freenetfs.py", + "fcp/genkey.py", + "fcp/get.py", + "fcp/invertkey.py", + "fcp/names.py", "fcp/node.py", + "fcp/put.py", + "fcp/redirect.py", + "fcp/sitemgr.py", + "fcp/xmlobject.py", + "fcp/xmlrpc.py", + "manpages/fcpgenkey.1", + "manpages/fcpgenkey.1.html", + "manpages/fcpget.1", + "manpages/fcpget.1.html", + "manpages/fcpinvertkey.1", + "manpages/fcpinvertkey.1.html", + "manpages/fcpnames.1", + "manpages/fcpnames.1.html", + "manpages/fcpput.1", + "manpages/fcpput.1.html", + "manpages/fcpredirect.1", + "manpages/fcpredirect.1.html", + "manpages/fproxyproxy.1", + "manpages/fproxyproxy.1.html", + "manpages/freesitemgr.1", + "manpages/freesitemgr.1.html", + "AUTHORS", + "BUGS", + "CHANGELOG", + "COPYING", + "CREDITS", + "INSTALL", + "INSTALL.es", + "README", + "README.es", + "README.freedisk", "bogon-bn-agg.txt", + "botplugin.py.dist", + "fcp_to_mrtg_bridge.py", + "fcp_to_rrdtool_bridge.py", + "fcpgenkey", + "fcpget", + "fcpinvertkey", + "fcpnames", + "fcpput", + "fcpredirect", + "fcpxmlrpc.cgi", + "fproxyproxy", + "freedisk", + "freedisk.conf", + "freesitemgr", + "manpages/fcpgenkey.1", + "manpages/fcpgenkey.1.html", + "manpages/fcpget.1", + "manpages/fcpget.1.html", + "manpages/fcpinvertkey.1", + "manpages/fcpinvertkey.1.html", + "manpages/fcpnames.1", + "manpages/fcpnames.1.html", + "manpages/fcpput.1", + "manpages/fcpput.1.html", + "manpages/fcpredirect.1", + "manpages/fcpredirect.1.html", + "manpages/fproxyproxy.1", + "manpages/fproxyproxy.1.html", + "manpages/freesitemgr.1", + "manpages/freesitemgr.1.html", + "minibot.py", "refbot.py", - "minibot.py", + "rrdtool_freenet.sh.example", + "setup.py", + "tutorial.py", ]; updater_backup_url = "https://emu.freenetproject.org/svn/trunk/apps/pyFreenet/updater.py"; # A second way to update ourself in case the first one changes URLs or something updater_filename = "updater.py"; @@ -256,8 +327,9 @@ for file_to_update in files_to_update: if( -1 != file_to_update.find( "/" )): file_to_update_dir = os.path.dirname( file_to_update ); + file_to_update_dir = file_to_update_dir + "/"; if( not file_to_update_dir in subdirs ): - subdirs.append( file_to_update_dir + "/" ); + subdirs.append( file_to_update_dir ); for subdir in subdirs: subdir_url = base_url + subdir; subdir_url_lines = []; From zothar at freenetproject.org Sun Jul 15 17:00:08 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Sun, 15 Jul 2007 17:00:08 +0000 (UTC) Subject: [Pyfreenet] r14141 - trunk/apps/pyFreenet Message-ID: <20070715170008.41EF147991A@freenetproject.org> Author: zothar Date: 2007-07-15 17:00:08 +0000 (Sun, 15 Jul 2007) New Revision: 14141 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: Bump the minimum node build to 1044. Refactor code a little so we don't complain about connecting to the node when we have actually connected fine and had a different problem. Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2007-07-15 16:50:35 UTC (rev 14140) +++ trunk/apps/pyFreenet/refbot.py 2007-07-15 17:00:08 UTC (rev 14141) @@ -63,7 +63,7 @@ bogon_filename = "bogon-bn-agg.txt"; # Get updates from http://www.cymru.com/Documents/bogon-bn-agg.txt bogons = {}; - minimumNodeBuild = 998; + minimumNodeBuild = 1044; svnLongRevision = "$Revision$" svnRevision = svnLongRevision[ 11 : -2 ] versions_filename = "updater_versions.dat"; @@ -357,31 +357,31 @@ log("Verifying connectivity with node.... (If this hangs, there are problems talking to the node's FCP service)") try: f = fcp.FCPNode( host = self.fcp_host, port = self.fcp_port ) - log("Successfully connected to the node's FCP service....") - log("Verifying node build version....") - if( f.nodeBuild < self.minimumNodeBuild ): - f.shutdown() - log("***"); - log("*** ERROR: This version of the refbot requires your node be running build %d or higher. Please upgrade your Freenet node and try again." % ( self.minimumNodeBuild )) - log("***"); - my_exit( 1 ) - try: - noderef = f.refstats(); - if( type( noderef ) == type( [] )): - noderef = noderef[ 0 ]; - self.nodeIdentity = noderef[ "identity" ]; - except Exception, msg: - f.shutdown() - log("***"); - log("*** ERROR: Failed to get the node's identity via FCP. This is an odd error this refbot developer is not sure of a reason for."); - log("***"); - my_exit( 1 ) except Exception, msg: f.shutdown() log("***"); log("*** ERROR: Failed to connect to node via FCP (%s:%d). Check your fcp host and port settings on both the node and the bot config." % ( self.fcp_host, self.fcp_port )); log("***"); my_exit( 1 ) + log("Successfully connected to the node's FCP service....") + log("Verifying node build version....") + if( f.nodeBuild < self.minimumNodeBuild ): + f.shutdown() + log("***"); + log("*** ERROR: This version of the refbot requires your node be running build %d or higher. Please upgrade your Freenet node and try again." % ( self.minimumNodeBuild )) + log("***"); + my_exit( 1 ) + try: + noderef = f.refstats(); + if( type( noderef ) == type( [] )): + noderef = noderef[ 0 ]; + self.nodeIdentity = noderef[ "identity" ]; + except Exception, msg: + f.shutdown() + log("***"); + log("*** ERROR: Failed to get the node's identity via FCP. This is an odd error this refbot developer is not sure of a reason for."); + log("***"); + my_exit( 1 ) del noderef[ "header" ]; self.nodeRef = noderef; From zothar at freenetproject.org Sun Jul 15 17:07:53 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Sun, 15 Jul 2007 17:07:53 +0000 (UTC) Subject: [Pyfreenet] r14142 - trunk/apps/pyFreenet Message-ID: <20070715170753.B6E7747A224@freenetproject.org> Author: zothar Date: 2007-07-15 17:07:53 +0000 (Sun, 15 Jul 2007) New Revision: 14142 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: rename nodeIdentity to nodeDarknetIdentity Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2007-07-15 17:00:08 UTC (rev 14141) +++ trunk/apps/pyFreenet/refbot.py 2007-07-15 17:07:53 UTC (rev 14142) @@ -375,7 +375,7 @@ noderef = f.refstats(); if( type( noderef ) == type( [] )): noderef = noderef[ 0 ]; - self.nodeIdentity = noderef[ "identity" ]; + self.nodeDarknetIdentity = noderef[ "identity" ]; except Exception, msg: f.shutdown() log("***"); @@ -448,7 +448,7 @@ if(ref_has_syntax_problem): self.setup_refurl( opts ); continue; - if( ref_fieldset[ "identity" ] != self.nodeIdentity ): + if( ref_fieldset[ "identity" ] != self.nodeDarknetIdentity ): log("***"); log("*** ERROR: The bot advertised ref's identity does not match the node's identity; perhaps your FCP host/port setting is wrong?"); log("***"); @@ -997,7 +997,7 @@ Ask for a bot's identity and send them ours """ if(self.bots.has_key( target ) and not self.bots[ target ].has_key( "identity" )): - self.privmsg( target, "getidentity %s" % ( self.nodeIdentity )) + self.privmsg( target, "getidentity %s" % ( self.nodeDarknetIdentity )) #@-node:sendGetIdentity #@+node:sendGetOptions @@ -1023,7 +1023,7 @@ """ Give them our identity """ - self.privmsg( target, "myidentity %s" % ( self.nodeIdentity )) + self.privmsg( target, "myidentity %s" % ( self.nodeDarknetIdentity )) #@-node:sendMyIdentity #@+node:sendMyOptions @@ -1100,7 +1100,7 @@ def addref(self, url, replyfunc, sender_irc_nick, peerRef = None, botAddType = None): log("** adding ref: %s" % url) - adderThread = AddRef(self.tmci_host, self.tmci_port, self.fcp_host, self.fcp_port, url, replyfunc, sender_irc_nick, self.irc_host, self.nodeIdentity, self.nodeRef, peerRef, botAddType) + adderThread = AddRef(self.tmci_host, self.tmci_port, self.fcp_host, self.fcp_port, url, replyfunc, sender_irc_nick, self.irc_host, self.nodeDarknetIdentity, self.nodeRef, peerRef, botAddType) self.adderThreads.append(adderThread) adderThread.start() @@ -1178,7 +1178,7 @@ del self.bots[ botNick ][ "ref" ] del self.bots[ botNick ][ "ref_terminated" ] return - if( ref_fieldset[ "identity" ] == self.nodeIdentity ): + if( ref_fieldset[ "identity" ] == self.nodeDarknetIdentity ): log("** bot using nick '%s' gave us our own node's ref." % ( botNick )); del self.bots[ botNick ][ "ref" ] del self.bots[ botNick ][ "ref_terminated" ] @@ -1780,7 +1780,7 @@ def cmd_identity(self, replyfunc, is_from_privmsg, args): self.privmsg( - "identity: %s" % (self.bot.nodeIdentity), + "identity: %s" % (self.bot.nodeDarknetIdentity), ) #@-node:cmd_identity @@ -1848,7 +1848,7 @@ minimumFCPAddNodeBuild = 1008; - def __init__(self, tmci_host, tmci_port, fcp_host, fcp_port, url, replyfunc, sender_irc_nick, irc_host, nodeIdentity, nodeRef, peerRef, botAddType): + def __init__(self, tmci_host, tmci_port, fcp_host, fcp_port, url, replyfunc, sender_irc_nick, irc_host, nodeDarknetIdentity, nodeRef, peerRef, botAddType): threading.Thread.__init__(self) self.tmci_host = tmci_host self.tmci_port = tmci_port @@ -1858,13 +1858,13 @@ self.replyfunc = replyfunc self.sender_irc_nick = sender_irc_nick self.irc_host = irc_host - self.nodeIdentity = nodeIdentity + self.nodeDarknetIdentity = nodeDarknetIdentity self.nodeRef = nodeRef self.peerRef = peerRef self.botAddType = botAddType self.status = 0 self.error_msg = None - self.plugin_args = { "fcp_module" : fcp, "tmci_host" : self.tmci_host, "tmci_port" : self.tmci_port, "fcp_host" : self.fcp_host, "fcp_port" : self.fcp_port, "sender_irc_nick" : self.sender_irc_nick, "irc_host" : self.irc_host, "log_function" : log, "reply_function" : self.replyfunc, "nodeIdentity" : self.nodeIdentity, "nodeRef" : self.nodeRef, "botAddType" : self.botAddType }; + self.plugin_args = { "fcp_module" : fcp, "tmci_host" : self.tmci_host, "tmci_port" : self.tmci_port, "fcp_host" : self.fcp_host, "fcp_port" : self.fcp_port, "sender_irc_nick" : self.sender_irc_nick, "irc_host" : self.irc_host, "log_function" : log, "reply_function" : self.replyfunc, "nodeIdentity" : self.nodeDarknetIdentity, "nodeRef" : self.nodeRef, "botAddType" : self.botAddType }; def run(self): if( self.peerRef == None ): @@ -1901,7 +1901,7 @@ self.status = -1 # invalid ref found at URL self.error_msg = "No %s field in ref" % ( require_ref_field ); return - if( ref_fieldset[ "identity" ] == self.nodeIdentity ): + if( ref_fieldset[ "identity" ] == self.nodeDarknetIdentity ): self.status = -5 self.error_msg = "Node already has a ref with its own identity" f.shutdown(); From zothar at freenetproject.org Sun Jul 15 17:14:05 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Sun, 15 Jul 2007 17:14:05 +0000 (UTC) Subject: [Pyfreenet] r14144 - trunk/apps/pyFreenet Message-ID: <20070715171405.55209479822@freenetproject.org> Author: zothar Date: 2007-07-15 17:14:05 +0000 (Sun, 15 Jul 2007) New Revision: 14144 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: more -> darknet related renaming Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2007-07-15 17:13:28 UTC (rev 14143) +++ trunk/apps/pyFreenet/refbot.py 2007-07-15 17:14:05 UTC (rev 14144) @@ -353,7 +353,7 @@ if needToSave: self.save() - self.nodeRef = {}; + self.nodeDarknetRef = {}; log("Verifying connectivity with node.... (If this hangs, there are problems talking to the node's FCP service)") try: f = fcp.FCPNode( host = self.fcp_host, port = self.fcp_port ) @@ -372,18 +372,29 @@ log("***"); my_exit( 1 ) try: - noderef = f.refstats(); - if( type( noderef ) == type( [] )): - noderef = noderef[ 0 ]; - self.nodeDarknetIdentity = noderef[ "identity" ]; + node_darknet_ref = f.refstats(); + if( type( node_darknet_ref ) == type( [] )): + node_darknet_ref = node_darknet_ref[ 0 ]; + self.nodeDarknetIdentity = node_darknet_ref[ "identity" ]; except Exception, msg: f.shutdown() log("***"); - log("*** ERROR: Failed to get the node's identity via FCP. This is an odd error this refbot developer is not sure of a reason for."); + log("*** ERROR: Failed to get the node's Darknet identity via FCP. This is an odd error this refbot developer is not sure of a reason for."); log("***"); my_exit( 1 ) - del noderef[ "header" ]; - self.nodeRef = noderef; + self.hasOpennet = False; + #try: + # nodeconfig = f.getconfig(); + # if( type( nodeconfig ) == type( [] )): + # nodeconfig = nodeconfig[ 0 ]; + #except Exception, msg: + # f.shutdown() + # log("***"); + # log("*** ERROR: Failed to get the node's Darknet identity via FCP. This is an odd error this refbot developer is not sure of a reason for."); + # log("***"); + # my_exit( 1 ) + del node_darknet_ref[ "header" ]; + self.nodeDarknetRef = node_darknet_ref; if( 0 >= len( FreenetNodeRefBot.bogons.keys())): readBogonFile( FreenetNodeRefBot.bogon_filename, self.addBogonCIDRNet ); @@ -1100,7 +1111,7 @@ def addref(self, url, replyfunc, sender_irc_nick, peerRef = None, botAddType = None): log("** adding ref: %s" % url) - adderThread = AddRef(self.tmci_host, self.tmci_port, self.fcp_host, self.fcp_port, url, replyfunc, sender_irc_nick, self.irc_host, self.nodeDarknetIdentity, self.nodeRef, peerRef, botAddType) + adderThread = AddRef(self.tmci_host, self.tmci_port, self.fcp_host, self.fcp_port, url, replyfunc, sender_irc_nick, self.irc_host, self.nodeDarknetIdentity, self.nodeDarknetRef, peerRef, botAddType) self.adderThreads.append(adderThread) adderThread.start() @@ -1386,8 +1397,8 @@ #@+node:sendrefdirect def sendrefdirect(self, peernick, is_bot ): - nodeRefKeys = self.nodeRef.keys() - nodeRefKeys.sort() + nodeDarknetRefKeys = self.nodeDarknetRef.keys() + nodeDarknetRefKeys.sort() log( "** sendrefdirect(): sendRefDirectLock.acquire() before processing peernick: %s" % ( peernick )); self.sendRefDirectLock.acquire( 1 ); # Spread out the lines of the ref so we don't trigger the babbler detector of a receiving refbot @@ -1399,8 +1410,8 @@ self.nextWhenTime = now; beginningNextWhenTime = self.nextWhenTime; log( "** DEBUG: before: nextWhen: %d nextWhenTime: %d" % ( nextWhen, self.nextWhenTime )); - for nodeRefKey in nodeRefKeys: - self.after( nextWhen, self.privmsg, peernick, "refdirect %s=%s" % ( nodeRefKey, self.nodeRef[ nodeRefKey ] )) + for nodeDarknetRefKey in nodeDarknetRefKeys: + self.after( nextWhen, self.privmsg, peernick, "refdirect %s=%s" % ( nodeDarknetRefKey, self.nodeDarknetRef[ nodeDarknetRefKey ] )) delay = random.randint(7,14) # 7-14 seconds between each line nextWhen += delay; self.nextWhenTime += delay; @@ -1848,7 +1859,7 @@ minimumFCPAddNodeBuild = 1008; - def __init__(self, tmci_host, tmci_port, fcp_host, fcp_port, url, replyfunc, sender_irc_nick, irc_host, nodeDarknetIdentity, nodeRef, peerRef, botAddType): + def __init__(self, tmci_host, tmci_port, fcp_host, fcp_port, url, replyfunc, sender_irc_nick, irc_host, nodeDarknetIdentity, nodeDarknetRef, peerRef, botAddType): threading.Thread.__init__(self) self.tmci_host = tmci_host self.tmci_port = tmci_port @@ -1859,12 +1870,12 @@ self.sender_irc_nick = sender_irc_nick self.irc_host = irc_host self.nodeDarknetIdentity = nodeDarknetIdentity - self.nodeRef = nodeRef + self.nodeDarknetRef = nodeDarknetRef self.peerRef = peerRef self.botAddType = botAddType self.status = 0 self.error_msg = None - self.plugin_args = { "fcp_module" : fcp, "tmci_host" : self.tmci_host, "tmci_port" : self.tmci_port, "fcp_host" : self.fcp_host, "fcp_port" : self.fcp_port, "sender_irc_nick" : self.sender_irc_nick, "irc_host" : self.irc_host, "log_function" : log, "reply_function" : self.replyfunc, "nodeIdentity" : self.nodeDarknetIdentity, "nodeRef" : self.nodeRef, "botAddType" : self.botAddType }; + self.plugin_args = { "fcp_module" : fcp, "tmci_host" : self.tmci_host, "tmci_port" : self.tmci_port, "fcp_host" : self.fcp_host, "fcp_port" : self.fcp_port, "sender_irc_nick" : self.sender_irc_nick, "irc_host" : self.irc_host, "log_function" : log, "reply_function" : self.replyfunc, "nodeIdentity" : self.nodeDarknetIdentity, "nodeRef" : self.nodeDarknetRef, "botAddType" : self.botAddType }; def run(self): if( self.peerRef == None ): From zothar at freenetproject.org Sun Jul 15 17:25:02 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Sun, 15 Jul 2007 17:25:02 +0000 (UTC) Subject: [Pyfreenet] r14145 - trunk/apps/pyFreenet/fcp Message-ID: <20070715172502.562B647A1FA@freenetproject.org> Author: zothar Date: 2007-07-15 17:25:02 +0000 (Sun, 15 Jul 2007) New Revision: 14145 Modified: trunk/apps/pyFreenet/fcp/node.py Log: pyFreenet: add GetConfig support with getconfig() Modified: trunk/apps/pyFreenet/fcp/node.py =================================================================== --- trunk/apps/pyFreenet/fcp/node.py 2007-07-15 17:14:05 UTC (rev 14144) +++ trunk/apps/pyFreenet/fcp/node.py 2007-07-15 17:25:02 UTC (rev 14145) @@ -1070,6 +1070,30 @@ return finalResult #@-node:putdir + #@+node:getconfig + def getconfig(self, **kw): + """ + Gets node configuration + + Keywords: + - async - whether to do this call asynchronously, and + return a JobTicket object + - callback - if given, this should be a callable which accepts 2 + arguments: + - status - will be one of 'successful', 'failed' or 'pending' + - value - depends on status: + - if status is 'successful', this will contain the value + returned from the command + - if status is 'failed' or 'pending', this will contain + a dict containing the response from node + - WithCurrent - default False - if True, the current configuration settings will be returned in the "current" tree of the ConfigData message fieldset + - WithShortDescription - default False - if True, the configuration setting short descriptions will be returned in the "shortDescription" tree of the ConfigData message fieldset + - other keywords, which are the same as for the FCP message and documented in the wiki: http://wiki.freenetproject.org/FCP2p0GetConfig + """ + + return self._submitCmd("__global", "GetConfig", **kw) + + #@-node:getconfig #@+node:invertprivate def invertprivate(self, privatekey): """ @@ -2095,6 +2119,17 @@ return # ----------------------------- + # handle ConfigData + if hdr == 'ConfigData': + # return all the data recieved + job.callback('successful', msg) + job._putResult(msg) + + # remove job from queue + self.jobs.pop(id, None) + return + + # ----------------------------- # handle progress messages if hdr == 'StartedCompression': From zothar at freenetproject.org Sun Jul 15 17:47:38 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Sun, 15 Jul 2007 17:47:38 +0000 (UTC) Subject: [Pyfreenet] r14146 - trunk/apps/pyFreenet Message-ID: <20070715174738.07C9D47991C@freenetproject.org> Author: zothar Date: 2007-07-15 17:47:37 +0000 (Sun, 15 Jul 2007) New Revision: 14146 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: now grab the opennet ref and identity from the node Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2007-07-15 17:25:02 UTC (rev 14145) +++ trunk/apps/pyFreenet/refbot.py 2007-07-15 17:47:37 UTC (rev 14146) @@ -353,6 +353,7 @@ if needToSave: self.save() + self.nodeDarknetIdentity = None; self.nodeDarknetRef = {}; log("Verifying connectivity with node.... (If this hangs, there are problems talking to the node's FCP service)") try: @@ -379,22 +380,40 @@ except Exception, msg: f.shutdown() log("***"); - log("*** ERROR: Failed to get the node's Darknet identity via FCP. This is an odd error this refbot developer is not sure of a reason for."); + log("*** ERROR: Failed to get the node's darknet identity via FCP. This is an odd error this refbot developer is not sure of a reason for."); log("***"); my_exit( 1 ) - self.hasOpennet = False; - #try: - # nodeconfig = f.getconfig(); - # if( type( nodeconfig ) == type( [] )): - # nodeconfig = nodeconfig[ 0 ]; - #except Exception, msg: - # f.shutdown() - # log("***"); - # log("*** ERROR: Failed to get the node's Darknet identity via FCP. This is an odd error this refbot developer is not sure of a reason for."); - # log("***"); - # my_exit( 1 ) del node_darknet_ref[ "header" ]; self.nodeDarknetRef = node_darknet_ref; + self.hasOpennet = False; + self.nodeOpennetIdentity = None; + self.nodeOpennetRef = {}; + try: + nodeconfig = f.getconfig( WithCurrent = True ); + if( type( nodeconfig ) == type( [] )): + nodeconfig = nodeconfig[ 0 ]; + if( nodeconfig.has_key( "current.node.opennet.enabled" ) and "true" == nodeconfig[ "current.node.opennet.enabled" ].lower() ): + self.hasOpennet = True; + except Exception, msg: + f.shutdown() + log("***"); + log("*** ERROR: Failed to get the node's opennet enabled status via FCP. This is an odd error this refbot developer is not sure of a reason for."); + log("***"); + my_exit( 1 ) + if( self.hasOpennet ): + try: + node_opennet_ref = f.refstats( GiveOpennetRef = True ); + if( type( node_opennet_ref ) == type( [] )): + node_opennet_ref = node_opennet_ref[ 0 ]; + self.nodeOpennetIdentity = node_opennet_ref[ "identity" ]; + except Exception, msg: + f.shutdown() + log("***"); + log("*** ERROR: Failed to get the node's opennet identity via FCP even though opennet is enabled. This is an odd error this refbot developer is not sure of a reason for."); + log("***"); + my_exit( 1 ) + del node_opennet_ref[ "header" ]; + self.nodeOpennetRef = node_opennet_ref; if( 0 >= len( FreenetNodeRefBot.bogons.keys())): readBogonFile( FreenetNodeRefBot.bogon_filename, self.addBogonCIDRNet ); From zothar at freenetproject.org Sun Jul 15 18:37:39 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Sun, 15 Jul 2007 18:37:39 +0000 (UTC) Subject: [Pyfreenet] r14147 - trunk/apps/pyFreenet Message-ID: <20070715183739.16DD847A313@freenetproject.org> Author: zothar Date: 2007-07-15 18:37:38 +0000 (Sun, 15 Jul 2007) New Revision: 14147 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: Add a little more feedback during startup. Also, add "darknet" to a few log/error messages. Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2007-07-15 17:47:37 UTC (rev 14146) +++ trunk/apps/pyFreenet/refbot.py 2007-07-15 18:37:38 UTC (rev 14147) @@ -372,6 +372,7 @@ log("*** ERROR: This version of the refbot requires your node be running build %d or higher. Please upgrade your Freenet node and try again." % ( self.minimumNodeBuild )) log("***"); my_exit( 1 ) + log("Getting node's darknet ref....") try: node_darknet_ref = f.refstats(); if( type( node_darknet_ref ) == type( [] )): @@ -388,6 +389,7 @@ self.hasOpennet = False; self.nodeOpennetIdentity = None; self.nodeOpennetRef = {}; + log("Checking if node has opennet enabled....") try: nodeconfig = f.getconfig( WithCurrent = True ); if( type( nodeconfig ) == type( [] )): @@ -401,6 +403,7 @@ log("***"); my_exit( 1 ) if( self.hasOpennet ): + log("Getting node's opennet ref....") try: node_opennet_ref = f.refstats( GiveOpennetRef = True ); if( type( node_opennet_ref ) == type( [] )): @@ -429,11 +432,11 @@ #log("DEBUG: url_ip: %s" % ( url_ip )); if( self.findBogonCIDRNet( url_ip )): log("***"); - log("*** ERROR: The bot advertised ref URL points to an RFC1918 private IP address or an unassigned bogon IP address and cannot be used on the Internet."); + log("*** ERROR: The bot advertised darknet ref URL points to an RFC1918 private IP address or an unassigned bogon IP address and cannot be used on the Internet."); log("***"); self.setup_refurl( opts ); continue; - log("Getting the bot advertised ref from URL..."); + log("Getting the bot advertised darknet ref from URL..."); try: openurl = urllib2.urlopen(opts['refurl']) refbuf = openurl.read(20*1024) # read up to 20 KiB @@ -443,11 +446,11 @@ refmemfile.close(); except Exception, msg: log("***"); - log("*** ERROR: Failed to get the bot advertised ref from URL."); + log("*** ERROR: Failed to get the bot advertised darknet ref from URL."); log("***"); self.setup_refurl( opts ); continue; - log("Checking syntax of advertised ref..."); + log("Checking syntax of advertised darknet ref..."); ref_fieldset = {}; end_found = False for refline in reflines: @@ -480,43 +483,43 @@ continue; if( ref_fieldset[ "identity" ] != self.nodeDarknetIdentity ): log("***"); - log("*** ERROR: The bot advertised ref's identity does not match the node's identity; perhaps your FCP host/port setting is wrong?"); + log("*** ERROR: The bot advertised darknet ref's identity does not match the node's identity; perhaps your FCP host/port setting is wrong?"); log("***"); self.setup_refurl( opts ); continue; - log("Test adding advertised ref..."); + log("Test adding advertised darknet ref..."); try: addpeer_result = f.addpeer( kwdict = ref_fieldset ) except fcp.node.FCPException, msg: if( 21 == msg.info[ 'Code' ] ): log("***"); - log("*** ERROR: The node had trouble parsing the bot advertised ref"); + log("*** ERROR: The node had trouble parsing the bot advertised darknet ref"); log("***"); self.setup_refurl( opts ); continue; elif( 27 == msg.info[ 'Code' ] ): log("***"); - log("*** ERROR: The node could not verify the signature of the bot advertised ref"); + log("*** ERROR: The node could not verify the signature of the bot advertised darknet ref"); log("***"); self.setup_refurl( opts ); continue; elif( 28 == msg.info[ 'Code' ] ): - log("The bot advertised ref appears to be good"); + log("The bot advertised darknet ref appears to be good"); break; elif( 29 == msg.info[ 'Code' ] ): log("***"); - log("*** ERROR: The node has a peer with the bot advertised ref; perhaps your FCP host/port setting is wrong?"); + log("*** ERROR: The node has a peer with the bot advertised darknet ref; perhaps your FCP host/port setting is wrong?"); log("***"); f.shutdown() my_exit( 1 ) log("***"); - log("*** ERROR: The node had trouble test-adding the bot advertised ref and gave us an unexpected error; perhaps you need to run updater.py"); + log("*** ERROR: The node had trouble test-adding the bot advertised darknet ref and gave us an unexpected error; perhaps you need to run updater.py"); log("***"); f.shutdown() my_exit( 1 ) except Exception, msg: log("***"); - log("*** ERROR: caught generic exception adding peer: %s" % ( msg )); + log("*** ERROR: caught generic exception test-adding darknet ref as peer: %s" % ( msg )); log("***"); f.shutdown() my_exit( 1 ) From zothar at freenetproject.org Sun Jul 15 18:51:36 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Sun, 15 Jul 2007 18:51:36 +0000 (UTC) Subject: [Pyfreenet] r14148 - trunk/apps/pyFreenet Message-ID: <20070715185136.3617C47A075@freenetproject.org> Author: zothar Date: 2007-07-15 18:51:36 +0000 (Sun, 15 Jul 2007) New Revision: 14148 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: Better minimum revision checking for fcp/node.py and minibot.py Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2007-07-15 18:37:38 UTC (rev 14147) +++ trunk/apps/pyFreenet/refbot.py 2007-07-15 18:51:36 UTC (rev 14148) @@ -63,6 +63,8 @@ bogon_filename = "bogon-bn-agg.txt"; # Get updates from http://www.cymru.com/Documents/bogon-bn-agg.txt bogons = {}; + minimumFCPNodeRevision = 14145; + minimumMiniBotRevision = 11957; minimumNodeBuild = 1044; svnLongRevision = "$Revision$" svnRevision = svnLongRevision[ 11 : -2 ] @@ -78,6 +80,23 @@ self.bots = {} self.botAnnouncePool = [] self.botIdentities = {} + + # check that we've got a revision capable fcp/node.py (must be before using it) + try: + fcpnodepy_revision = fcp.FCPNode.svnRevision; + except: + log("***"); + log("*** This version of the refbot requires a newer version of fcp/node.py. Please run updater.py and try again."); + log("***"); + my_exit( 1 ); + # check that we've got a revision capable minibot.py (must be before using it) + try: + minibotpy_revision = MiniBot.svnRevision; + except: + log("***"); + log("*** This version of the refbot requires a newer version of minibot.py. Please run updater.py and try again."); + log("***"); + my_exit( 1 ); log("Starting refbot with the following file versions: refbot.py: r%s minibot.py: r%s fcp/node.py: r%s" % (FreenetNodeRefBot.svnRevision, MiniBot.svnRevision, fcp.FCPNode.svnRevision)) @@ -108,14 +127,19 @@ log("***"); my_exit( 1 ); - # check that we've got an updated fcp/node.py - try: - fcpnodepy_revision = fcp.FCPNode.svnRevision; - except: + # check that we've got an up-to-date fcp/node.py + if( self.minimumFCPNodeRevision > int( fcp.FCPNode.svnRevision )): log("***"); - log("*** This version of the refbot requires a newer version of fcp/node.py. Please run updater.py and try again."); + log("*** This version of the refbot requires at least revision %s of fcp/node.py. Please run updater.py and try again." % ( self.minimumFCPNodeRevision )); log("***"); my_exit( 1 ); + + # check that we've got an up-to-date minibot.py + if( self.minimumMiniBotRevision > int( MiniBot.svnRevision )): + log("***"); + log("*** This version of the refbot requires at least revision %s of minibot.py. Please run updater.py and try again." % ( self.minimumMiniBotRevision )); + log("***"); + my_exit( 1 ); # determine a config file path if not cfgFile: From zothar at freenetproject.org Sun Jul 15 20:40:44 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Sun, 15 Jul 2007 20:40:44 +0000 (UTC) Subject: [Pyfreenet] r14150 - trunk/apps/pyFreenet Message-ID: <20070715204044.D7D244793F3@freenetproject.org> Author: zothar Date: 2007-07-15 20:40:44 +0000 (Sun, 15 Jul 2007) New Revision: 14150 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: Added more opennet stuff and did a few more -> darknet pieces. Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2007-07-15 18:56:48 UTC (rev 14149) +++ trunk/apps/pyFreenet/refbot.py 2007-07-15 20:40:44 UTC (rev 14150) @@ -511,6 +511,12 @@ log("***"); self.setup_refurl( opts ); continue; + if( ref_fieldset[ "identity" ] == self.nodeOpennetIdentity ): + log("***"); + log("*** ERROR: The bot advertised darknet ref's identity matches the node's opennet identity; perhaps you've got your ref URLs mixed up?"); + log("***"); + self.setup_refurl( opts ); + continue; log("Test adding advertised darknet ref..."); try: addpeer_result = f.addpeer( kwdict = ref_fieldset ) @@ -917,6 +923,10 @@ identity = self.bots[ sender ][ "identity" ] if( self.botIdentities.has_key( identity )): del self.botIdentities[ identity ] + if( self.bots[ sender ].has_key( "opennet_identity" )): + identity = self.bots[ sender ][ "opennet_identity" ] + if( self.botIdentities.has_key( identity )): + del self.botIdentities[ identity ] if( sender in self.botAnnouncePool ): self.botAnnouncePool.remove( sender ); del self.bots[ sender ] @@ -942,6 +952,20 @@ return True; #@-node:addBotIdentity + #@+node:addBotOpennetIdentity + def addBotOpennetIdentity(self, botNick, botIdentity ): + + if( self.botOpennetIdentities.has_key( botIdentity )): + return False; + if( not self.bots.has_key( botNick )): + return False; + if( self.bots[ botNick ].has_key( "opennet_identity" )): + return False; + self.bots[ botNick ][ "opennet_identity" ] = botIdentity; + self.botOpennetIdentities[ botIdentity ] = botNick; + return True; + + #@-node:addBotOpennetIdentity #@+node:getPeerUpdate def getPeerUpdate(self): @@ -1051,12 +1075,30 @@ #@+node:sendGetIdentity def sendGetIdentity(self, target): """ - Ask for a bot's identity and send them ours + Ask for a bot's darknet identity and send them ours """ if(self.bots.has_key( target ) and not self.bots[ target ].has_key( "identity" )): self.privmsg( target, "getidentity %s" % ( self.nodeDarknetIdentity )) #@-node:sendGetIdentity + #@+node:sendGetOpennetIdentity + def sendGetOpennetIdentity(self, target): + """ + Ask for a bot's opennet identity and send them ours + """ + if(self.bots.has_key( target ) and not self.bots[ target ].has_key( "opennet_identity" )): + self.privmsg( target, "getopennetidentity %s" % ( self.nodeOpennetIdentity )) + + #@-node:sendGetOpennetIdentity + #@+node:sendGetOpennetRefDirect + def sendGetOpennetRefDirect(self, target): + """ + Get their opennet ref directly + """ + if(self.bots.has_key( target ) and not self.bots[ target ].has_key( "opennet_ref" )): + self.privmsg( target, "getopennetrefdirect" ) + + #@-node:sendGetOpennetRefDirect #@+node:sendGetOptions def sendGetOptions(self, target): """ @@ -1069,7 +1111,7 @@ #@+node:sendGetRefDirect def sendGetRefDirect(self, target): """ - Give them our identity + Get their darknet ref directly """ if(self.bots.has_key( target ) and not self.bots[ target ].has_key( "ref" )): self.privmsg( target, "getrefdirect" ) @@ -1078,11 +1120,19 @@ #@+node:sendMyIdentity def sendMyIdentity(self, target): """ - Give them our identity + Give them our darknet identity """ self.privmsg( target, "myidentity %s" % ( self.nodeDarknetIdentity )) #@-node:sendMyIdentity + #@+node:sendMyOpennetIdentity + def sendMyOpennetIdentity(self, target): + """ + Give them our opennet identity + """ + self.privmsg( target, "myopennetidentity %s" % ( self.nodeOpennetIdentity )) + + #@-node:sendMyIdentity #@+node:sendMyOptions def sendMyOptions(self, target): """ @@ -1157,7 +1207,7 @@ def addref(self, url, replyfunc, sender_irc_nick, peerRef = None, botAddType = None): log("** adding ref: %s" % url) - adderThread = AddRef(self.tmci_host, self.tmci_port, self.fcp_host, self.fcp_port, url, replyfunc, sender_irc_nick, self.irc_host, self.nodeDarknetIdentity, self.nodeDarknetRef, peerRef, botAddType) + adderThread = AddRef(self.tmci_host, self.tmci_port, self.fcp_host, self.fcp_port, url, replyfunc, sender_irc_nick, self.irc_host, self.nodeDarknetIdentity, self.nodeDarknetRef, self.nodeOpennetIdentity, self.nodeOpennetRef, peerRef, botAddType) self.adderThreads.append(adderThread) adderThread.start() @@ -1236,10 +1286,15 @@ del self.bots[ botNick ][ "ref_terminated" ] return if( ref_fieldset[ "identity" ] == self.nodeDarknetIdentity ): - log("** bot using nick '%s' gave us our own node's ref." % ( botNick )); + log("** bot using nick '%s' gave us our own node's darknet ref." % ( botNick )); del self.bots[ botNick ][ "ref" ] del self.bots[ botNick ][ "ref_terminated" ] return + if( ref_fieldset[ "identity" ] == self.nodeOpennetIdentity ): + log("** bot using nick '%s' gave us our own node's opennet ref." % ( botNick )); + del self.bots[ botNick ][ "ref" ] + del self.bots[ botNick ][ "ref_terminated" ] + return if( ref_fieldset[ "identity" ] != botIdentity ): log("** bot using nick '%s' gave us a ref that doesn't match the identity they claimed they have: %s" % ( botNick, botIdentity )); del self.bots[ botNick ][ "ref" ] @@ -1336,7 +1391,7 @@ if( adderThread.botAddType == "request" ): self.after(random.randint(7, 20), self.sendDoRefSwapAllow, adderThread.sender_irc_nick) # After 7-20 seconds, agree to swap refs with them else: - self.after(random.randint(7, 20), self.sendDoRefSwapCompleted, adderThread.sender_irc_nick) # After 7-20 seconds, agree to swap refs with them + self.after(2, self.sendDoRefSwapCompleted, adderThread.sender_irc_nick) # After 2 seconds, tell them we've completed the swap self.nrefs += 1 refs_to_go = self.number_of_refs_to_collect - self.nrefs refs_plural_str = '' @@ -1854,6 +1909,19 @@ self.bot.check_identity_with_node( peerIdentity ) #@-node:cmd_myidentity + #@+node:cmd_myopennetidentity + def cmd_myopennetidentity(self, replyfunc, is_from_privmsg, args): + + if( 1 == len( args ) and self.bot.bots.has_key( self.peernick )): + peerIdentity = args[ 0 ]; + if( not self.bot.botIdentities.has_key( peerIdentity )): + self.bot.addBotIdentity( self.peernick, peerIdentity ) + log("** botIdentities: %s" % ( self.bot.botIdentities.keys() )) + if( self.bot.bot2bot_trades_enabled ): + if( self.bot.check_bot_peer_has_option( self.peernick, "bot2bot_trades" )): + self.bot.check_identity_with_node( peerIdentity ) + + #@-node:cmd_myopennetidentity #@+node:cmd_myoptions def cmd_myoptions(self, replyfunc, is_from_privmsg, args): @@ -1864,6 +1932,28 @@ self.after(random.randint(7, 20), self.bot.sendGetIdentity, self.peernick) # Ask for their identity after 7-20 seconds #@-node:cmd_myoptions + #@+node:cmd_opennetIdentity + def cmd_opennetIdentity(self, replyfunc, is_from_privmsg, args): + + self.privmsg( + "opennetIdentity: %s" % (self.bot.nodeOpennetIdentity), + ) + + #@-node:cmd_opennetIdentity + #@+node:cmd_opennetrefdirect + def cmd_opennetrefdirect(self, replyfunc, is_from_privmsg, args): + + args = string.join( args, " " ); + if( self.bot.bots.has_key( self.peernick )): + peerRefLine = args; + if( not self.bot.bots[ self.peernick ].has_key( "opennet_ref" )): + self.bot.bots[ self.peernick ][ "opennet_ref" ] = [] + self.bot.bots[ self.peernick ][ "opennet_ref" ].append( peerRefLine ) + if("end" == peerRefLine.lower()): + self.bot.bots[ self.peernick ][ "opennet_ref_terminated" ] = True + self.bot.check_ref_from_bot_and_act( self.peernick ) + + #@-node:cmd_opennetrefdirect #@+node:cmd_options def cmd_options(self, replyfunc, is_from_privmsg, args): @@ -1905,7 +1995,7 @@ minimumFCPAddNodeBuild = 1008; - def __init__(self, tmci_host, tmci_port, fcp_host, fcp_port, url, replyfunc, sender_irc_nick, irc_host, nodeDarknetIdentity, nodeDarknetRef, peerRef, botAddType): + def __init__(self, tmci_host, tmci_port, fcp_host, fcp_port, url, replyfunc, sender_irc_nick, irc_host, nodeDarknetIdentity, nodeDarknetRef, nodeOpennetIdentity, nodeOpennetRef, peerRef, botAddType): threading.Thread.__init__(self) self.tmci_host = tmci_host self.tmci_port = tmci_port @@ -1917,11 +2007,13 @@ self.irc_host = irc_host self.nodeDarknetIdentity = nodeDarknetIdentity self.nodeDarknetRef = nodeDarknetRef + self.nodeOpennetIdentity = nodeOpennetIdentity + self.nodeOpennetRef = nodeOpennetRef self.peerRef = peerRef self.botAddType = botAddType self.status = 0 self.error_msg = None - self.plugin_args = { "fcp_module" : fcp, "tmci_host" : self.tmci_host, "tmci_port" : self.tmci_port, "fcp_host" : self.fcp_host, "fcp_port" : self.fcp_port, "sender_irc_nick" : self.sender_irc_nick, "irc_host" : self.irc_host, "log_function" : log, "reply_function" : self.replyfunc, "nodeIdentity" : self.nodeDarknetIdentity, "nodeRef" : self.nodeDarknetRef, "botAddType" : self.botAddType }; + self.plugin_args = { "fcp_module" : fcp, "tmci_host" : self.tmci_host, "tmci_port" : self.tmci_port, "fcp_host" : self.fcp_host, "fcp_port" : self.fcp_port, "sender_irc_nick" : self.sender_irc_nick, "irc_host" : self.irc_host, "log_function" : log, "reply_function" : self.replyfunc, "nodeIdentity" : self.nodeDarknetIdentity, "nodeRef" : self.nodeDarknetRef, "nodeOpennetIdentity" : self.nodeOpennetIdentity, "nodeOpennetRef" : self.nodeOpennetRef, "botAddType" : self.botAddType }; def run(self): if( self.peerRef == None ): @@ -1963,6 +2055,11 @@ self.error_msg = "Node already has a ref with its own identity" f.shutdown(); return + if( ref_fieldset[ "identity" ] == self.nodeOpennetIdentity ): + self.status = -5 + self.error_msg = "Node already has a ref with its own identity" + f.shutdown(); + return try: f = fcp.FCPNode( host = self.fcp_host, port = self.fcp_port ) From zothar at freenetproject.org Sun Jul 15 20:55:34 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Sun, 15 Jul 2007 20:55:34 +0000 (UTC) Subject: [Pyfreenet] r14151 - trunk/apps/pyFreenet Message-ID: <20070715205534.9442647A2F0@freenetproject.org> Author: zothar Date: 2007-07-15 20:55:34 +0000 (Sun, 15 Jul 2007) New Revision: 14151 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: comment out a few debugging lines Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2007-07-15 20:40:44 UTC (rev 14150) +++ trunk/apps/pyFreenet/refbot.py 2007-07-15 20:55:34 UTC (rev 14151) @@ -1500,7 +1500,7 @@ nodeDarknetRefKeys = self.nodeDarknetRef.keys() nodeDarknetRefKeys.sort() - log( "** sendrefdirect(): sendRefDirectLock.acquire() before processing peernick: %s" % ( peernick )); + #log( "** sendrefdirect(): sendRefDirectLock.acquire() before processing peernick: %s" % ( peernick )); self.sendRefDirectLock.acquire( 1 ); # Spread out the lines of the ref so we don't trigger the babbler detector of a receiving refbot nextWhen = 0; @@ -1510,15 +1510,15 @@ else: self.nextWhenTime = now; beginningNextWhenTime = self.nextWhenTime; - log( "** DEBUG: before: nextWhen: %d nextWhenTime: %d" % ( nextWhen, self.nextWhenTime )); + #log( "** DEBUG: before: nextWhen: %d nextWhenTime: %d" % ( nextWhen, self.nextWhenTime )); for nodeDarknetRefKey in nodeDarknetRefKeys: self.after( nextWhen, self.privmsg, peernick, "refdirect %s=%s" % ( nodeDarknetRefKey, self.nodeDarknetRef[ nodeDarknetRefKey ] )) delay = random.randint(7,14) # 7-14 seconds between each line nextWhen += delay; self.nextWhenTime += delay; self.after( nextWhen, self.privmsg, peernick, "refdirect End" ) - log( "** DEBUG: after: nextWhen: %d nextWhenTime: %d beginningNextWhenTime: %d diff: %d" % ( nextWhen, self.nextWhenTime, beginningNextWhenTime, self.nextWhenTime - beginningNextWhenTime )); - log( "** sendrefdirect(): sendRefDirectLock.release() after processing peernick: %s" % ( peernick )); + #log( "** DEBUG: after: nextWhen: %d nextWhenTime: %d beginningNextWhenTime: %d diff: %d" % ( nextWhen, self.nextWhenTime, beginningNextWhenTime, self.nextWhenTime - beginningNextWhenTime )); + #log( "** sendrefdirect(): sendRefDirectLock.release() after processing peernick: %s" % ( peernick )); self.sendRefDirectLock.release(); #@-node:sendrefdirect From zothar at freenetproject.org Sun Jul 15 22:43:25 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Sun, 15 Jul 2007 22:43:25 +0000 (UTC) Subject: [Pyfreenet] r14152 - trunk/apps/pyFreenet Message-ID: <20070715224325.DCF5B479850@freenetproject.org> Author: zothar Date: 2007-07-15 22:43:25 +0000 (Sun, 15 Jul 2007) New Revision: 14152 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: Fix a long standing bug: two bots can now finish exchanging refs when one node already had the other's ref before the conversation started. More opennet stuff. Swapping opennet refs with humans is probably pretty close now. Probably gonna wants some extra help from the node for bot2bot opennet trades for efficiency reasons. Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2007-07-15 20:55:34 UTC (rev 14151) +++ trunk/apps/pyFreenet/refbot.py 2007-07-15 22:43:25 UTC (rev 14152) @@ -495,6 +495,12 @@ log("*** ERROR: Advertised ref does not contain an \"End\" line."); log("***"); ref_has_syntax_problem = True; + if( ref_fieldset.has_key( "opennet" ) and "true" == ref_fieldset[ "opennet" ].lower() ): + log("***"); + log("*** ERROR: The bot advertised darknet ref is really an opennet ref; perhaps you've got your ref URLs mixed up?"); + log("***"); + self.setup_refurl( opts ); + continue; required_ref_fields = [ "dsaGroup.g", "dsaGroup.p", "dsaGroup.q", "dsaPubKey.y", "identity", "location", "myName", "sig" ]; for require_ref_field in required_ref_fields: if(not ref_fieldset.has_key(require_ref_field)): @@ -953,16 +959,16 @@ #@-node:addBotIdentity #@+node:addBotOpennetIdentity - def addBotOpennetIdentity(self, botNick, botIdentity ): + def addBotOpennetIdentity(self, botNick, botOpennetIdentity ): - if( self.botOpennetIdentities.has_key( botIdentity )): + if( self.botOpennetIdentities.has_key( botOpennetIdentity )): return False; if( not self.bots.has_key( botNick )): return False; if( self.bots[ botNick ].has_key( "opennet_identity" )): return False; - self.bots[ botNick ][ "opennet_identity" ] = botIdentity; - self.botOpennetIdentities[ botIdentity ] = botNick; + self.bots[ botNick ][ "opennet_identity" ] = botOpennetIdentity; + self.botOpennetIdentities[ botOpennetIdentity ] = botNick; return True; #@-node:addBotOpennetIdentity @@ -1207,7 +1213,7 @@ def addref(self, url, replyfunc, sender_irc_nick, peerRef = None, botAddType = None): log("** adding ref: %s" % url) - adderThread = AddRef(self.tmci_host, self.tmci_port, self.fcp_host, self.fcp_port, url, replyfunc, sender_irc_nick, self.irc_host, self.nodeDarknetIdentity, self.nodeDarknetRef, self.nodeOpennetIdentity, self.nodeOpennetRef, peerRef, botAddType) + adderThread = AddRef(self.tmci_host, self.tmci_port, self.fcp_host, self.fcp_port, url, replyfunc, sender_irc_nick, self.irc_host, self.nodeDarknetIdentity, self.nodeDarknetRef, self.hasOpennet, self.nodeOpennetIdentity, self.nodeOpennetRef, peerRef, botAddType) self.adderThreads.append(adderThread) adderThread.start() @@ -1222,16 +1228,16 @@ return False; #@-node:check_bot_peer_has_option - #@+node:check_bot_peer_is_connected - def check_bot_peer_is_connected( self, botNick ): + #@+node:check_bot_peer_is_already_added + def check_bot_peer_is_already_added( self, botNick ): if( not self.bots.has_key( botNick )): return False; - if( self.bots[ botNick ].has_key( "connected" ) and self.bots[ botNick ][ "connected" ] ): + if( self.bots[ botNick ].has_key( "already_added" ) and self.bots[ botNick ][ "already_added" ] ): return True; return False; - #@-node:check_bot_peer_is_connected + #@-node:check_bot_peer_is_already_added #@+node:check_identity_with_node def check_identity_with_node(self, botIdentity): @@ -1359,11 +1365,11 @@ if( not self.bots.has_key( botNick )): log("** checked bot nick (%s) we don't have a bots entry for. They must have disconnected." % ( botNick )); continue - if( self.check_bot_peer_is_connected( botNick )): + if( self.check_bot_peer_is_already_added( botNick )): continue if(1 == status): self.privmsg( botNick, "havepeer" ); - self.bots[ botNick ][ "connected" ] = True; + self.bots[ botNick ][ "already_added" ] = True; elif( 0 == status ): if( self.bots[ botNick ].has_key( "ref" ) and self.bots[ botNick ].has_key( "ref_terminated" ) and self.bots[ botNick ].has_key( "ref_is_good" )): self.privmsg( botNick, "haveref" ); @@ -1729,6 +1735,8 @@ if( self.bot.check_bot_peer_has_option( self.peernick, "bot2bot_trades" )): if( self.bot.bots[ self.peernick ].has_key( "ref" ) and self.bot.bots[ self.peernick ].has_key( "ref_terminated" ) and self.bot.bots[ self.peernick ].has_key( "ref_is_good" )): self.bot.addref( "(from bot: %s)" % ( self.peernick ), replyfunc, self.peernick, self.bot.bots[ self.peernick ][ "ref" ], "allow" ) + elif( self.bot.bots[ self.peernick ].has_key( "already_added" )): + self.after(2, self.bot.sendDoRefSwapCompleted, self.peernick) # After 2 seconds, tell them we've completed the swap (since we already had the peer added to the node) #@-node:cmd_dorefswapallow #@+node:cmd_dorefswapcompleted @@ -1802,7 +1810,7 @@ if( not self.bot.botIdentities.has_key( peerIdentity )): self.bot.addBotIdentity( self.peernick, peerIdentity ); log("** botIdentities: %s" % ( self.bot.botIdentities.keys() )) - if( not self.bot.check_bot_peer_is_connected( self.peernick )): + if( not self.bot.check_bot_peer_is_already_added( self.peernick )): if( self.bot.bot2bot_trades_enabled ): if( self.bot.check_bot_peer_has_option( self.peernick, "bot2bot_trades" )): self.bot.check_identity_with_node( peerIdentity ) @@ -1844,14 +1852,14 @@ #@+node:cmd_havepeer def cmd_havepeer(self, replyfunc, is_from_privmsg, args): if( 1 == len( args ) and self.bot.bots.has_key( self.peernick )): - self.bot.bots[ self.peernick ][ "connected" ] = True; + self.bot.bots[ self.peernick ][ "already_added" ] = True; #@-node:cmd_havepeer #@+node:cmd_haveref def cmd_haveref(self, replyfunc, is_from_privmsg, args): if( self.bot.bot2bot_trades_enabled ): if( self.bot.check_bot_peer_has_option( self.peernick, "bot2bot_trades" )): - if( self.bot.bots[ self.peernick ].has_key( "ref" ) and self.bot.bots[ self.peernick ].has_key( "ref_terminated" ) and self.bot.bots[ self.peernick ].has_key( "ref_is_good" )): + if( self.bot.bots[ self.peernick ].has_key( "already_added" ) or ( self.bot.bots[ self.peernick ].has_key( "ref" ) and self.bot.bots[ self.peernick ].has_key( "ref_terminated" ) and self.bot.bots[ self.peernick ].has_key( "ref_is_good" ))): self.after(random.randint(7, 20), self.bot.sendDoRefSwapRequest, self.peernick) # Ask to swap refs with them after 7-20 seconds #@-node:cmd_haveref @@ -1995,7 +2003,7 @@ minimumFCPAddNodeBuild = 1008; - def __init__(self, tmci_host, tmci_port, fcp_host, fcp_port, url, replyfunc, sender_irc_nick, irc_host, nodeDarknetIdentity, nodeDarknetRef, nodeOpennetIdentity, nodeOpennetRef, peerRef, botAddType): + def __init__(self, tmci_host, tmci_port, fcp_host, fcp_port, url, replyfunc, sender_irc_nick, irc_host, nodeDarknetIdentity, nodeDarknetRef, hasOpennet, nodeOpennetIdentity, nodeOpennetRef, peerRef, botAddType): threading.Thread.__init__(self) self.tmci_host = tmci_host self.tmci_port = tmci_port @@ -2007,6 +2015,7 @@ self.irc_host = irc_host self.nodeDarknetIdentity = nodeDarknetIdentity self.nodeDarknetRef = nodeDarknetRef + self.hasOpennet = hasOpennet self.nodeOpennetIdentity = nodeOpennetIdentity self.nodeOpennetRef = nodeOpennetRef self.peerRef = peerRef From zothar at freenetproject.org Wed Jul 18 21:52:22 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Wed, 18 Jul 2007 21:52:22 +0000 (UTC) Subject: [Pyfreenet] r14179 - in trunk/apps/pyFreenet: . fcp Message-ID: <20070718215222.78B7847A222@freenetproject.org> Author: zothar Date: 2007-07-18 21:52:22 +0000 (Wed, 18 Jul 2007) New Revision: 14179 Modified: trunk/apps/pyFreenet/fcp/node.py trunk/apps/pyFreenet/refbot.py Log: refbot: The bot can now trade opennet refs with humans. The bot does not yet trade opennet refs with other bots. Modified: trunk/apps/pyFreenet/fcp/node.py =================================================================== --- trunk/apps/pyFreenet/fcp/node.py 2007-07-18 21:11:26 UTC (rev 14178) +++ trunk/apps/pyFreenet/fcp/node.py 2007-07-18 21:52:22 UTC (rev 14179) @@ -1290,6 +1290,28 @@ return self._submitCmd("__global", "AddPeer", **kw) #@-node:addpeer + #@+node:listpeer + def listpeer(self, **kw): + """ + Modify settings on one of the node's peers + + Keywords: + - async - whether to do this call asynchronously, and + return a JobTicket object + - callback - if given, this should be a callable which accepts 2 + arguments: + - status - will be one of 'successful', 'failed' or 'pending' + - value - depends on status: + - if status is 'successful', this will contain the value + returned from the command + - if status is 'failed' or 'pending', this will contain + a dict containing the response from node + - NodeIdentifier - one of name (except for opennet peers), identity or IP:port for the desired peer + """ + + return self._submitCmd("__global", "ListPeer", **kw) + + #@-node:listpeer #@+node:modifypeer def modifypeer(self, **kw): """ Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2007-07-18 21:11:26 UTC (rev 14178) +++ trunk/apps/pyFreenet/refbot.py 2007-07-18 21:52:22 UTC (rev 14179) @@ -42,7 +42,7 @@ ident = 'FreenetRefBot' -current_config_version = 3 +current_config_version = 4 obscenities = ["fuck", "cunt", "shit", "asshole", "fscking", "wank"] reactToObscenities = False @@ -65,7 +65,7 @@ bogons = {}; minimumFCPNodeRevision = 14145; minimumMiniBotRevision = 11957; - minimumNodeBuild = 1044; + minimumNodeBuild = 1045; svnLongRevision = "$Revision$" svnRevision = svnLongRevision[ 11 : -2 ] versions_filename = "updater_versions.dat"; @@ -260,17 +260,61 @@ self.bot2bot_trades_only_configured = False needToSave = True if(not self.bot2bot_configured and self.bot2bot_trades_only_configured): - print "bot2bot communication is disabled, but trading with other bots only is enabled. This does not make sense. Quitting." + log("***"); + log("*** bot2bot communication is disabled, but trading with other bots only is enabled. This does not make sense. Quitting."); + log("***"); my_exit( 1 ); if(not self.bot2bot_trades_configured and self.bot2bot_trades_only_configured): - print "bot2bot ref trading is disabled, but trading with other bots only is enabled. This does not make sense. Quitting." + log("***"); + log("*** bot2bot ref trading is disabled, but trading with other bots only is enabled. This does not make sense. Quitting."); + log("***"); my_exit( 1 ); if(self.config_version < 3 and (not opts.has_key('privmsg_only') or (opts.has_key('privmsg_only') and opts['privmsg_only'] == 'y'))): self.setup_privmsg_only( opts ) self.refurl = opts['refurl'] - if('' == self.refurl and not self.bot2bot_trades_only_configured): - print "configured to trade with humans using a noderef url, but we don't know a noderef url. This does not make sense. Quitting." + if(self.config_version < 4 and not opts.has_key('darknet_trades_only')): + self.setup_darknet_trades_only( opts ) + needToSave = True + if(opts.has_key('darknet_trades_only')): + if( opts['darknet_trades_only'] == 'y' ): + self.darknet_trades_only_configured = True + else: + self.darknet_trades_only_configured = False + else: + opts['darknet_trades_only'] = 'n'; + self.darknet_trades_only_configured = False + needToSave = True + if(self.config_version < 4 and not opts.has_key('opennet_trades_only')): + self.setup_opennet_trades_only( opts ) + needToSave = True + if(opts.has_key('opennet_trades_only')): + if( opts['opennet_trades_only'] == 'y' ): + self.opennet_trades_only_configured = True + else: + self.opennet_trades_only_configured = False + else: + opts['opennet_trades_only'] = 'n'; + self.opennet_trades_only_configured = False + needToSave = True + if(self.config_version < 4 and not opts.has_key('opennet_refurl')): + self.setup_opennet_refurl( opts ) + needToSave = True + self.opennet_refurl = opts['opennet_refurl'] + if('' == self.refurl and not self.bot2bot_trades_only_configured and not self.opennet_trades_only_configured): + log("***"); + log("*** configured to trade with humans using a darknet noderef url, but we don't know a darknet noderef url. This does not make sense. Quitting."); + log("***"); my_exit( 1 ); + if('' == self.opennet_refurl and not self.bot2bot_trades_only_configured and not self.darknet_trades_only_configured): + log("***"); + log("*** configured to trade with humans using a opennet noderef url, but we don't know a opennet noderef url. This does not make sense. Quitting."); + log("***"); + my_exit( 1 ); + if(self.bot2bot_trades_only_configured and self.opennet_trades_only_configured): + log("***"); + log("*** configured to trade only with bots and to only trade opennet refs. This is a problem because bot2bot trading does not yet support trading opennet refs. Quitting."); # **FIXME** + log("***"); + my_exit( 1 ); if(opts.has_key('privmsg_only')): if( opts['privmsg_only'] == 'y' ): self.privmsg_only_configured = True @@ -355,6 +399,12 @@ self.bot2bot_announces_enabled = True; # **FIXME** hardcoded ATM self.bot2bot_trades_enabled = self.bot2bot_trades_configured; self.bot2bot_trades_only_enabled = self.bot2bot_trades_only_configured; + self.darknet_trades_enabled = True; + if( self.opennet_trades_only_configured ): + self.darknet_trades_enabled = False; + self.opennet_trades_enabled = True; + if( self.darknet_trades_only_configured ): + self.opennet_trades_enabled = False; self.privmsg_only_enabled = self.privmsg_only_configured; if( not self.bot2bot_enabled and self.bot2bot_announces_enabled ): self.bot2bot_announces_enabled = False; @@ -383,7 +433,10 @@ try: f = fcp.FCPNode( host = self.fcp_host, port = self.fcp_port ) except Exception, msg: - f.shutdown() + try: + f.shutdown() + except UnboundLocalError, msg: + pass log("***"); log("*** ERROR: Failed to connect to node via FCP (%s:%d). Check your fcp host and port settings on both the node and the bot config." % ( self.fcp_host, self.fcp_port )); log("***"); @@ -446,7 +499,9 @@ readBogonFile( FreenetNodeRefBot.bogon_filename, self.addBogonCIDRNet ); #log("DEBUG: bogons: %s" % ( FreenetNodeRefBot.bogons )); - while( 'y' != opts['bot2bot_trades_only'] ): + # Testing advertised darknet ref URL + log("DEBUG: self.darknet_trades_enabled: %s" % ( self.darknet_trades_enabled )); + while( 'y' != opts['bot2bot_trades_only'] and self.darknet_trades_enabled ): ( url_scheme, url_netloc, url_path, url_parms, url_query, url_fragid ) = urlparse.urlparse( opts['refurl'] ); url_host = url_netloc; if( -1 != url_host.find( ":" )): @@ -495,6 +550,12 @@ log("*** ERROR: Advertised ref does not contain an \"End\" line."); log("***"); ref_has_syntax_problem = True; + if( ref_fieldset.has_key( "testnet" ) and "true" == ref_fieldset[ "testnet" ].lower() ): + log("***"); + log("*** ERROR: The bot advertised darknet ref is really an testnet ref. The bot does not currently support testnet ref trading."); + log("***"); + self.setup_refurl( opts ); + continue; if( ref_fieldset.has_key( "opennet" ) and "true" == ref_fieldset[ "opennet" ].lower() ): log("***"); log("*** ERROR: The bot advertised darknet ref is really an opennet ref; perhaps you've got your ref URLs mixed up?"); @@ -513,7 +574,7 @@ continue; if( ref_fieldset[ "identity" ] != self.nodeDarknetIdentity ): log("***"); - log("*** ERROR: The bot advertised darknet ref's identity does not match the node's identity; perhaps your FCP host/port setting is wrong?"); + log("*** ERROR: The bot advertised darknet ref's identity does not match the node's darknet identity; perhaps your FCP host/port setting is wrong?"); log("***"); self.setup_refurl( opts ); continue; @@ -564,6 +625,134 @@ except Exception, msg: pass; break; + + # Testing advertised opennet ref URL + log("DEBUG: self.opennet_trades_enabled: %s" % ( self.opennet_trades_enabled )); + while( 'y' != opts['bot2bot_trades_only'] and self.opennet_trades_enabled ): + ( url_scheme, url_netloc, url_path, url_parms, url_query, url_fragid ) = urlparse.urlparse( opts['opennet_refurl'] ); + url_host = url_netloc; + if( -1 != url_host.find( ":" )): + url_host_fields = url_host.split( ":" ); + url_host = url_host_fields[ 0 ]; + url_ip = socket.gethostbyname( url_host ); + #log("DEBUG: url_ip: %s" % ( url_ip )); + if( self.findBogonCIDRNet( url_ip )): + log("***"); + log("*** ERROR: The bot advertised opennet ref URL points to an RFC1918 private IP address or an unassigned bogon IP address and cannot be used on the Internet."); + log("***"); + self.setup_opennet_refurl( opts ); + continue; + log("Getting the bot advertised opennet ref from URL..."); + try: + openurl = urllib2.urlopen(opts['opennet_refurl']) + refbuf = openurl.read(20*1024) # read up to 20 KiB + openurl.close() + refmemfile = StringIO.StringIO(refbuf) + reflines = refmemfile.readlines() + refmemfile.close(); + except Exception, msg: + log("***"); + log("*** ERROR: Failed to get the bot advertised opennet ref from URL."); + log("***"); + self.setup_opennet_refurl( opts ); + continue; + log("Checking syntax of advertised opennet ref..."); + ref_fieldset = {}; + end_found = False + for refline in reflines: + refline = refline.strip(); + if("" == refline): + continue; + if("end" == refline.lower()): + end_found = True + break; + reflinefields = refline.split("=", 1) + if(2 != len(reflinefields)): + continue; + if(not ref_fieldset.has_key(reflinefields[ 0 ])): + ref_fieldset[ reflinefields[ 0 ]] = reflinefields[ 1 ] + ref_has_syntax_problem = False; + if(not end_found): + log("***"); + log("*** ERROR: Advertised ref does not contain an \"End\" line."); + log("***"); + ref_has_syntax_problem = True; + if( ref_fieldset.has_key( "testnet" ) and "true" == ref_fieldset[ "testnet" ].lower() ): + log("***"); + log("*** ERROR: The bot advertised opennet ref is really an testnet ref. The bot does not currently support testnet ref trading."); + log("***"); + self.setup_refurl( opts ); + continue; + if( not ref_fieldset.has_key( "opennet" ) or ( ref_fieldset.has_key( "opennet" ) and "false" == ref_fieldset[ "opennet" ].lower() )): + log("***"); + log("*** ERROR: The bot advertised opennet ref is really a darknet ref; perhaps you've got your ref URLs mixed up?"); + log("***"); + self.setup_opennet_refurl( opts ); + continue; + required_ref_fields = [ "dsaGroup.g", "dsaGroup.p", "dsaGroup.q", "dsaPubKey.y", "identity", "location", "opennet", "sig" ]; + for require_ref_field in required_ref_fields: + if(not ref_fieldset.has_key(require_ref_field)): + log("***"); + log("*** ERROR: No %s field in ref" % ( require_ref_field )); + log("***"); + ref_has_syntax_problem = True; + if(ref_has_syntax_problem): + self.setup_opennet_refurl( opts ); + continue; + if( ref_fieldset[ "identity" ] != self.nodeOpennetIdentity ): + log("***"); + log("*** ERROR: The bot advertised opennet ref's identity does not match the node's opennet identity; perhaps your FCP host/port setting is wrong?"); + log("***"); + self.setup_opennet_refurl( opts ); + continue; + if( ref_fieldset[ "identity" ] == self.nodeDarknetIdentity ): + log("***"); + log("*** ERROR: The bot advertised opennet ref's identity matches the node's darknet identity; perhaps you've got your ref URLs mixed up?"); + log("***"); + self.setup_opennet_refurl( opts ); + continue; + log("Test adding advertised opennet ref..."); + try: + addpeer_result = f.addpeer( kwdict = ref_fieldset ) + except fcp.node.FCPException, msg: + if( 21 == msg.info[ 'Code' ] ): + log("***"); + log("*** ERROR: The node had trouble parsing the bot advertised opennet ref"); + log("***"); + self.setup_opennet_refurl( opts ); + continue; + elif( 27 == msg.info[ 'Code' ] ): + log("***"); + log("*** ERROR: The node could not verify the signature of the bot advertised opennet ref"); + log("***"); + self.setup_opennet_refurl( opts ); + continue; + elif( 28 == msg.info[ 'Code' ] ): + log("The bot advertised opennet ref appears to be good"); + break; + elif( 29 == msg.info[ 'Code' ] ): + log("***"); + log("*** ERROR: The node has a peer with the bot advertised opennet ref; perhaps your FCP host/port setting is wrong?"); + log("***"); + f.shutdown() + my_exit( 1 ) + log("***"); + log("*** ERROR: The node had trouble test-adding the bot advertised opennet ref and gave us an unexpected error; perhaps you need to run updater.py"); + log("***"); + f.shutdown() + my_exit( 1 ) + except Exception, msg: + log("***"); + log("*** ERROR: caught generic exception test-adding opennet ref as peer: %s" % ( msg )); + log("***"); + f.shutdown() + my_exit( 1 ) + try: + f.removepeer(ref_fieldset[ "identity" ] ); + except Exception, msg: + pass; + break; + f.shutdown() self.nrefs = 0 @@ -672,7 +861,11 @@ self.setup_bot2bot_trades( opts ) self.setup_bot2bot_trades_only( opts ) opts['refurl'] = ''; - self.setup_refurl( opts ); + opts['opennet_refurl'] = ''; + self.setup_darknet_trades_only( opts ) + self.setup_opennet_trades_only( opts ) + self.setup_refurl( opts ) + self.setup_opennet_refurl( opts ) self.setup_privmsg_only( opts ) opts['greetinterval'] = 1800 @@ -739,6 +932,18 @@ opts['bot2bot_trades_only'] = 'n'; #@-node:setup_bot2bot_trades_only + #@+node:setup_darknet_trades_only + def setup_darknet_trades_only(self, opts): + """ + """ + while 1: + opts['darknet_trades_only'] = self.prompt("Should we trade only darknet refs?", "n") + opts['darknet_trades_only'] = opts['darknet_trades_only'].lower(); + if( opts['darknet_trades_only'] in [ 'y', 'n' ] ): + break; + print "Invalid option '%s' - must be 'y' for yes or 'n' for no" % opts['darknet_trades_only'] + + #@-node:setup_darknet_trades_only #@+node:setup_privmsg_only def setup_privmsg_only(self, opts): """ @@ -754,12 +959,37 @@ opts['privmsg_only'] = 'y'; #@-node:setup_privmsg_only + #@+node:setup_opennet_refurl + def setup_opennet_refurl(self, opts): + """ + """ + if( 'y' != opts['bot2bot_trades_only'] and 'y' != opts['darknet_trades_only'] ): + opts['opennet_refurl'] = self.prompt("URL of your node's opennet ref") + else: + opts['opennet_refurl'] = ''; + + #@-node:setup_opennet_refurl + #@+node:setup_opennet_trades_only + def setup_opennet_trades_only(self, opts): + """ + """ + if( 'y' != opts['darknet_trades_only'] ): + while 1: + opts['opennet_trades_only'] = self.prompt("Should we trade only opennet refs?", "n") + opts['opennet_trades_only'] = opts['opennet_trades_only'].lower(); + if( opts['opennet_trades_only'] in [ 'y', 'n' ] ): + break; + print "Invalid option '%s' - must be 'y' for yes or 'n' for no" % opts['opennet_trades_only'] + else: + opts['opennet_trades_only'] = 'n'; + + #@-node:setup_opennet_trades_only #@+node:setup_refurl def setup_refurl(self, opts): """ """ - if( 'y' != opts['bot2bot_trades_only'] ): - opts['refurl'] = self.prompt("URL of your noderef") + if( 'y' != opts['bot2bot_trades_only'] and 'y' != opts['opennet_trades_only'] ): + opts['refurl'] = self.prompt("URL of your node's darknet ref") else: opts['refurl'] = ''; @@ -800,6 +1030,7 @@ f.write(fmt % ("fcp_host", repr(self.fcp_host))) f.write(fmt % ("fcp_port", repr(self.fcp_port))) f.write(fmt % ("refurl", repr(self.refurl))) + f.write(fmt % ("opennet_refurl", repr(self.opennet_refurl))) f.write(fmt % ("password", repr(self.password))) f.write(fmt % ("greetinterval", repr(self.greet_interval))) f.write(fmt % ("spaminterval", repr(self.spam_interval))) @@ -826,6 +1057,14 @@ f.write(fmt % ("privmsg_only", repr('y'))) else: f.write(fmt % ("privmsg_only", repr('n'))) + if(self.darknet_trades_only_configured): + f.write(fmt % ("darknet_trades_only", repr('y'))) + else: + f.write(fmt % ("darknet_only", repr('n'))) + if(self.opennet_trades_only_configured): + f.write(fmt % ("opennet_trades_only", repr('y'))) + else: + f.write(fmt % ("opennet_only", repr('n'))) f.close() @@ -1213,7 +1452,7 @@ def addref(self, url, replyfunc, sender_irc_nick, peerRef = None, botAddType = None): log("** adding ref: %s" % url) - adderThread = AddRef(self.tmci_host, self.tmci_port, self.fcp_host, self.fcp_port, url, replyfunc, sender_irc_nick, self.irc_host, self.nodeDarknetIdentity, self.nodeDarknetRef, self.hasOpennet, self.nodeOpennetIdentity, self.nodeOpennetRef, peerRef, botAddType) + adderThread = AddRef(self.tmci_host, self.tmci_port, self.fcp_host, self.fcp_port, url, replyfunc, sender_irc_nick, self.irc_host, self.nodeDarknetIdentity, self.nodeDarknetRef, self.hasOpennet, self.nodeOpennetIdentity, self.nodeOpennetRef, self.darknet_trades_enabled, self.opennet_trades_enabled, peerRef, botAddType) self.adderThreads.append(adderThread) adderThread.start() @@ -1423,7 +1662,10 @@ refs_to_go_str = " (%d ref%s to go)" % ( refs_to_go, refs_plural_str ) if(2 == adderThread.status): adderThread.replyfunc("while adding your ref, I noticed that it does not have a physical.udp line. Once you get a connection and that line is added to your ref, renew the URL you share with people (and bots)") - adderThread.replyfunc("added your ref. Now please add mine <%s> to create a peer connection.%s" % (self.refurl, refs_to_go_str)) + if(adderThread.isDarknetRef): + adderThread.replyfunc("added your ref. Now please add mine <%s> to create a peer connection.%s" % (self.refurl, refs_to_go_str)) + else: + adderThread.replyfunc("added your ref. Now please add mine <%s> to create a peer connection.%s" % (self.opennet_refurl, refs_to_go_str)) if self.nrefs >= self.number_of_refs_to_collect: log("Got our %d refs, now terminating!" % ( self.number_of_refs_to_collect )) self.after(3, self.thankChannelThenDie) @@ -1455,6 +1697,12 @@ error_str = adderThread.error_msg elif(-7 == adderThread.status): error_str = "the node could not add your peer for some reason. Gave it a corrupted ref maybe? It cannot be edited nor \"word wrapped\". Check your ref and try again. Ref not added." + elif(-8 == adderThread.status): + error_str = "this bot does not currently trade testnet node references. Ref not added." + elif(-9 == adderThread.status): + error_str = "this bot does not currently trade darknet node references. Ref not added." + elif(-10 == adderThread.status): + error_str = "this bot does not currently trade opennet node references. Ref not added." refs_to_go = self.number_of_refs_to_collect - self.nrefs refs_to_go_str = '' if refs_to_go > 0: @@ -1816,6 +2064,24 @@ self.bot.check_identity_with_node( peerIdentity ) #@-node:cmd_getidentity + #@+node:cmd_getopennetref + def cmd_getopennetref(self, replyfunc, is_from_privmsg, args): + + if( self.bot.bot2bot_trades_only_enabled ): + replyfunc("Sorry, I'm configured to only trade refs with other bots and to not trade directly with humans. Send me the \"help\" command to learn how to run your own ref swapping bot.") + return + if( self.bot.privmsg_only_enabled and not is_from_privmsg ): + replyfunc("Sorry, I'm configured to trade refs with humans only using private messages. Use the /msg command to send me a private message, after registering with nickserv if needed (i.e. /ns register ).") + return + if( self.bot.opennet_trades_enabled ): + if( self.bot.darknet_trades_enabled ): + replyfunc("Sorry, I'm not configured to trade opennet refs at the moment, but I will trade darknet refs. Try the \"getref\" command.") + else: + replyfunc("Sorry, I'm not configured to trade opennet refs at the moment.") + return + replyfunc("My ref is at %s" % self.bot.opennet_refurl) + + #@-node:cmd_getopennetref #@+node:cmd_getoptions def cmd_getoptions(self, replyfunc, is_from_privmsg, args): @@ -1834,6 +2100,12 @@ if( self.bot.privmsg_only_enabled and not is_from_privmsg ): replyfunc("Sorry, I'm configured to trade refs with humans only using private messages. Use the /msg command to send me a private message, after registering with nickserv if needed (i.e. /ns register ).") return + if( self.bot.darknet_trades_enabled ): + if( self.bot.opennet_trades_enabled ): + replyfunc("Sorry, I'm not configured to trade darknet refs at the moment, but I will trade opennet refs. Try the \"getopennetref\" command.") + else: + replyfunc("Sorry, I'm not configured to trade darknet refs at the moment.") + return replyfunc("My ref is at %s" % self.bot.refurl) #@-node:cmd_getref @@ -1872,15 +2144,22 @@ "If you do run your own copy of me, you'll want to run my updater.py script periodically to make sure you have my latest features and bug fixes.", "My version numbers are refbot.py at r%s and minibot.py at r%s" % (FreenetNodeRefBot.svnRevision, MiniBot.svnRevision), "Available commands:", - " help - display this help", - " version - display the above version information", - " die - terminate me (PM from owner only)" + " help - display this help", + " version - display the above version information", + " die - terminate me (PM from owner only)" ) if( not self.bot.bot2bot_trades_only_enabled ): self.privmsg( - " addref - add ref at to my node", - " getref - print out my own ref so you can add me" + " addref - add ref at to my node", ) + if( not self.bot.bot2bot_trades_only_enabled and self.bot.darknet_trades_enabled): + self.privmsg( + " getref - print out my own darknet ref so you can add me (assuming I already have yours)" + ) + if( not self.bot.bot2bot_trades_only_enabled and self.bot.opennet_trades_enabled): + self.privmsg( + " getopennetref - print out my own opennet ref so you can add me (assuming I already have yours)" + ) self.privmsg( "** (end of help listing) **" ) @@ -2003,7 +2282,7 @@ minimumFCPAddNodeBuild = 1008; - def __init__(self, tmci_host, tmci_port, fcp_host, fcp_port, url, replyfunc, sender_irc_nick, irc_host, nodeDarknetIdentity, nodeDarknetRef, hasOpennet, nodeOpennetIdentity, nodeOpennetRef, peerRef, botAddType): + def __init__(self, tmci_host, tmci_port, fcp_host, fcp_port, url, replyfunc, sender_irc_nick, irc_host, nodeDarknetIdentity, nodeDarknetRef, hasOpennet, nodeOpennetIdentity, nodeOpennetRef, darknet_trades_enabled, opennet_trades_enabled, peerRef, botAddType): threading.Thread.__init__(self) self.tmci_host = tmci_host self.tmci_port = tmci_port @@ -2018,11 +2297,16 @@ self.hasOpennet = hasOpennet self.nodeOpennetIdentity = nodeOpennetIdentity self.nodeOpennetRef = nodeOpennetRef + self.isDarknetRef = False + self.isOpennetRef = False + self.isTestnetRef = False + self.darknet_trades_enabled = darknet_trades_enabled + self.opennet_trades_enabled = opennet_trades_enabled self.peerRef = peerRef self.botAddType = botAddType self.status = 0 self.error_msg = None - self.plugin_args = { "fcp_module" : fcp, "tmci_host" : self.tmci_host, "tmci_port" : self.tmci_port, "fcp_host" : self.fcp_host, "fcp_port" : self.fcp_port, "sender_irc_nick" : self.sender_irc_nick, "irc_host" : self.irc_host, "log_function" : log, "reply_function" : self.replyfunc, "nodeIdentity" : self.nodeDarknetIdentity, "nodeRef" : self.nodeDarknetRef, "nodeOpennetIdentity" : self.nodeOpennetIdentity, "nodeOpennetRef" : self.nodeOpennetRef, "botAddType" : self.botAddType }; + self.plugin_args = { "fcp_module" : fcp, "tmci_host" : self.tmci_host, "tmci_port" : self.tmci_port, "fcp_host" : self.fcp_host, "fcp_port" : self.fcp_port, "sender_irc_nick" : self.sender_irc_nick, "irc_host" : self.irc_host, "log_function" : log, "reply_function" : self.replyfunc, "nodeIdentity" : self.nodeDarknetIdentity, "nodeRef" : self.nodeDarknetRef, "nodeOpennetIdentity" : self.nodeOpennetIdentity, "nodeOpennetRef" : self.nodeOpennetRef, "darknet_trades_enabled" : self.darknet_trades_enabled, "opennet_trades_enabled" : self.opennet_trades_enabled, "botAddType" : self.botAddType }; def run(self): if( self.peerRef == None ): @@ -2053,7 +2337,30 @@ continue; if(not ref_fieldset.has_key(reflinefields[ 0 ])): ref_fieldset[ reflinefields[ 0 ]] = reflinefields[ 1 ] - required_ref_fields = [ "dsaGroup.g", "dsaGroup.p", "dsaGroup.q", "dsaPubKey.y", "identity", "location", "myName", "sig" ]; + if( ref_fieldset.has_key( "testnet" ) and "true" == ref_fieldset[ "testnet" ].lower() ): + self.isTestnetRef = True; + if( self.isTestnetRef ): + self.status = -8 + self.error_msg = "Bot does not currently trade testnet refs" + return + if( ref_fieldset.has_key( "opennet" ) and "true" == ref_fieldset[ "opennet" ].lower() ): + self.isOpennetRef = True; + else: + self.isDarknetRef = True; + if( self.isDarknetRef and not self.darknet_trades_enabled): + self.status = -9 + self.error_msg = "Bot does not currently trade darknet refs" + return + if( self.isOpennetRef and not self.opennet_trades_enabled): + self.status = -10 + self.error_msg = "Bot does not currently trade opennet refs" + return + self.plugin_args[ "isDarknetRef" ] = self.isDarknetRef; + self.plugin_args[ "isOpennetRef" ] = self.isOpennetRef; + if( self.isDarknetRef ): + required_ref_fields = [ "dsaGroup.g", "dsaGroup.p", "dsaGroup.q", "dsaPubKey.y", "identity", "location", "myName", "sig" ]; + else: + required_ref_fields = [ "dsaGroup.g", "dsaGroup.p", "dsaGroup.q", "dsaPubKey.y", "identity", "location", "opennet", "sig" ]; for require_ref_field in required_ref_fields: if(not ref_fieldset.has_key(require_ref_field)): self.status = -1 # invalid ref found at URL @@ -2062,12 +2369,10 @@ if( ref_fieldset[ "identity" ] == self.nodeDarknetIdentity ): self.status = -5 self.error_msg = "Node already has a ref with its own identity" - f.shutdown(); return if( ref_fieldset[ "identity" ] == self.nodeOpennetIdentity ): self.status = -5 self.error_msg = "Node already has a ref with its own identity" - f.shutdown(); return try: @@ -2084,7 +2389,7 @@ return except Exception, msg: log("Got exception calling botplugin.pre_add(): %s" % ( msg )); - returned_peer = f.modifypeer( NodeIdentifier = ref_fieldset[ "identity" ] ) + returned_peer = f.listpeer( NodeIdentifier = ref_fieldset[ "identity" ] ) if( type( returned_peer ) == type( [] )): returned_peer = returned_peer[ 0 ]; if( returned_peer[ "header" ] == "Peer" ): @@ -2131,7 +2436,7 @@ return try: - returned_peer = f.modifypeer( NodeIdentifier = ref_fieldset[ "identity" ] ) + returned_peer = f.listpeer( NodeIdentifier = ref_fieldset[ "identity" ] ) if( type( returned_peer ) == type( [] )): returned_peer = returned_peer[ 0 ]; if( returned_peer[ "header" ] == "UnknownNodeIdentifier" ): @@ -2147,16 +2452,17 @@ plugin_result = botplugin.post_add( self.plugin_args ); except Exception, msg: log("Got exception calling botplugin.post_add(): %s" % ( msg )); - try: - if( self.peerRef == None ): - note_text = "%s added via refbot.py from %s@%s at %s" % ( ref_fieldset[ "myName" ], self.sender_irc_nick, self.irc_host, time.strftime( "%Y%m%d-%H%M%S", time.localtime() ) ) - else: - note_text = "%s bot2bot traded via refbot.py with %s@%s at %s" % ( ref_fieldset[ "myName" ], self.sender_irc_nick, self.irc_host, time.strftime( "%Y%m%d-%H%M%S", time.localtime() ) ) - encoded_note_text = base64.encodestring( note_text ).replace( "\r", "" ).replace( "\n", "" ); - f.modifypeernote( NodeIdentifier = ref_fieldset[ "identity" ], PeerNoteType = fcp.node.PEER_NOTE_PRIVATE_DARKNET_COMMENT, NoteText = encoded_note_text ) - except Exception, msg: - # We'll just not have added a private peer note if we get an exception here - pass + if(self.isDarknetRef): + try: + if( self.peerRef == None ): + note_text = "%s added via refbot.py from %s@%s at %s" % ( ref_fieldset[ "myName" ], self.sender_irc_nick, self.irc_host, time.strftime( "%Y%m%d-%H%M%S", time.localtime() ) ) + else: + note_text = "%s bot2bot traded via refbot.py with %s@%s at %s" % ( ref_fieldset[ "myName" ], self.sender_irc_nick, self.irc_host, time.strftime( "%Y%m%d-%H%M%S", time.localtime() ) ) + encoded_note_text = base64.encodestring( note_text ).replace( "\r", "" ).replace( "\n", "" ); + f.modifypeernote( NodeIdentifier = ref_fieldset[ "identity" ], PeerNoteType = fcp.node.PEER_NOTE_PRIVATE_DARKNET_COMMENT, NoteText = encoded_note_text ) + except Exception, msg: + # We'll just not have added a private peer note if we get an exception here + pass f.shutdown(); if(not ref_fieldset.has_key("physical.udp")): @@ -2179,7 +2485,7 @@ def run(self): try: f = fcp.FCPNode( host = self.fcp_host, port = self.fcp_port ) - returned_peer = f.modifypeer( NodeIdentifier = self.identity ) + returned_peer = f.listpeer( NodeIdentifier = self.identity ) if( type( returned_peer ) == type( [] )): returned_peer = returned_peer[ 0 ]; if( returned_peer[ "header" ] == "Peer" ): From zothar at freenetproject.org Wed Jul 18 22:49:16 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Wed, 18 Jul 2007 22:49:16 +0000 (UTC) Subject: [Pyfreenet] r14180 - trunk/apps/pyFreenet Message-ID: <20070718224916.5DDBB47A20E@freenetproject.org> Author: zothar Date: 2007-07-18 22:49:16 +0000 (Wed, 18 Jul 2007) New Revision: 14180 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: mention darknet and/or opennet when greeting the channel. Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2007-07-18 21:52:22 UTC (rev 14179) +++ trunk/apps/pyFreenet/refbot.py 2007-07-18 22:49:16 UTC (rev 14180) @@ -399,6 +399,8 @@ self.bot2bot_announces_enabled = True; # **FIXME** hardcoded ATM self.bot2bot_trades_enabled = self.bot2bot_trades_configured; self.bot2bot_trades_only_enabled = self.bot2bot_trades_only_configured; + self.darknet_trades_only_enabled = self.darknet_trades_only_configured; + self.opennet_trades_only_enabled = self.opennet_trades_only_configured; self.darknet_trades_enabled = True; if( self.opennet_trades_only_configured ): self.darknet_trades_enabled = False; @@ -1233,37 +1235,42 @@ refs_plural_str = '' if( refs_to_go > 1 ): refs_plural_str = "s" + dark_open_str = "darknet and opennet"; + if( self.darknet_trades_only_enabled ): + dark_open_str = "darknet"; + elif( self.darknet_trades_only_enabled ): + dark_open_str = "opennet"; if( self.bot2bot_trades_only_enabled ): self.privmsg( self.channel, - "Hi, I'm %s's noderef swap bot. I'm configured to only trade with other bots and will not trade directly with humans. Send me the \"help\" command to learn how to run your own ref swapping bot. (%d ref%s to go)" \ + "Hi, I'm %s's noderef swap bot. I'm configured to only trade refs with other bots and will not trade directly with humans. Send me the \"help\" command to learn how to run your own ref swapping bot. (%d ref%s to go)" \ % ( self.nodenick, refs_to_go, refs_plural_str ) ) elif( self.privmsg_only_enabled ): if( self.bot2bot_trades_enabled ): self.privmsg( self.channel, - "Hi, I'm %s's noderef swap bot. I'm configured to trade refs with bots and with humans only via private message (requires registering with nickserv, i.e. /ns register ). To swap a ref with me, /msg me with your ref url (%d ref%s to go)" \ - % ( self.nodenick, refs_to_go, refs_plural_str ) + "Hi, I'm %s's noderef swap bot. I'm configured to trade %s refs with bots and with humans only via private message (requires registering with nickserv, i.e. /ns register ). To swap a ref with me, /msg me with your ref url (%d ref%s to go)" \ + % ( self.nodenick, dark_open_str, refs_to_go, refs_plural_str ) ) else: self.privmsg( self.channel, "Hi, I'm %s's noderef swap bot. I'm configured to only trade refs with humans via private message (requires registering with nickserv, i.e. /ns register ) and will not trade with bots. To swap a ref with me, /msg me with your ref url (%d ref%s to go)" \ - % ( self.nodenick, refs_to_go, refs_plural_str ) + % ( self.nodenick, dark_open_str, refs_to_go, refs_plural_str ) ) else: if( self.bot2bot_trades_enabled ): self.privmsg( self.channel, - "Hi, I'm %s's noderef swap bot. I'm configured to trade with humans or bots. To swap a ref with me, /msg me or say %s: your_ref_url (%d ref%s to go)" \ - % ( self.nodenick, self.nick, refs_to_go, refs_plural_str ) + "Hi, I'm %s's noderef swap bot. I'm configured to trade %s refs with humans or bots. To swap a ref with me, /msg me or say %s: your_ref_url (%d ref%s to go)" \ + % ( self.nodenick, dark_open_str, self.nick, refs_to_go, refs_plural_str ) ) else: self.privmsg( self.channel, - "Hi, I'm %s's noderef swap bot. I'm configured to trade with humans, but not with bots. To swap a ref with me, /msg me or say %s: your_ref_url (%d ref%s to go)" \ - % ( self.nodenick, self.nick, refs_to_go, refs_plural_str ) + "Hi, I'm %s's noderef swap bot. I'm configured to trade %s refs with humans, but not with bots. To swap a ref with me, /msg me or say %s: your_ref_url (%d ref%s to go)" \ + % ( self.nodenick, dark_open_str, self.nick, refs_to_go, refs_plural_str ) ) if(self.greet_interval > 0 and not self.bot2bot_trades_only_enabled): self.after(self.greet_interval, self.greetChannel) @@ -2138,8 +2145,13 @@ #@+node:cmd_help def cmd_help(self, replyfunc, is_from_privmsg, args): + dark_open_str = "darknet and opennet"; + if( self.darknet_trades_only_enabled ): + dark_open_str = "darknet"; + elif( self.darknet_trades_only_enabled ): + dark_open_str = "opennet"; self.privmsg( - "I am a bot for exchanging freenet noderefs", + "I am a bot for exchanging freenet %s node references (refs)" % ( dark_open_str ), "I am part of pyfcp. To run your own copy of me, install pyfcp as detailed at http://wiki.freenetproject.org/Refbot and then run refbot.py", "If you do run your own copy of me, you'll want to run my updater.py script periodically to make sure you have my latest features and bug fixes.", "My version numbers are refbot.py at r%s and minibot.py at r%s" % (FreenetNodeRefBot.svnRevision, MiniBot.svnRevision), From zothar at freenetproject.org Wed Jul 18 22:56:51 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Wed, 18 Jul 2007 22:56:51 +0000 (UTC) Subject: [Pyfreenet] r14181 - trunk/apps/pyFreenet Message-ID: <20070718225651.BCA6D47A68C@freenetproject.org> Author: zothar Date: 2007-07-18 22:56:51 +0000 (Wed, 18 Jul 2007) New Revision: 14181 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: save the refurl after asking for it to be corrected by the user Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2007-07-18 22:49:16 UTC (rev 14180) +++ trunk/apps/pyFreenet/refbot.py 2007-07-18 22:56:51 UTC (rev 14181) @@ -502,7 +502,8 @@ #log("DEBUG: bogons: %s" % ( FreenetNodeRefBot.bogons )); # Testing advertised darknet ref URL - log("DEBUG: self.darknet_trades_enabled: %s" % ( self.darknet_trades_enabled )); + needToSave = False; + #log("DEBUG: self.darknet_trades_enabled: %s" % ( self.darknet_trades_enabled )); while( 'y' != opts['bot2bot_trades_only'] and self.darknet_trades_enabled ): ( url_scheme, url_netloc, url_path, url_parms, url_query, url_fragid ) = urlparse.urlparse( opts['refurl'] ); url_host = url_netloc; @@ -516,6 +517,7 @@ log("*** ERROR: The bot advertised darknet ref URL points to an RFC1918 private IP address or an unassigned bogon IP address and cannot be used on the Internet."); log("***"); self.setup_refurl( opts ); + needToSave = True; continue; log("Getting the bot advertised darknet ref from URL..."); try: @@ -530,6 +532,7 @@ log("*** ERROR: Failed to get the bot advertised darknet ref from URL."); log("***"); self.setup_refurl( opts ); + needToSave = True; continue; log("Checking syntax of advertised darknet ref..."); ref_fieldset = {}; @@ -557,12 +560,14 @@ log("*** ERROR: The bot advertised darknet ref is really an testnet ref. The bot does not currently support testnet ref trading."); log("***"); self.setup_refurl( opts ); + needToSave = True; continue; if( ref_fieldset.has_key( "opennet" ) and "true" == ref_fieldset[ "opennet" ].lower() ): log("***"); log("*** ERROR: The bot advertised darknet ref is really an opennet ref; perhaps you've got your ref URLs mixed up?"); log("***"); self.setup_refurl( opts ); + needToSave = True; continue; required_ref_fields = [ "dsaGroup.g", "dsaGroup.p", "dsaGroup.q", "dsaPubKey.y", "identity", "location", "myName", "sig" ]; for require_ref_field in required_ref_fields: @@ -573,18 +578,21 @@ ref_has_syntax_problem = True; if(ref_has_syntax_problem): self.setup_refurl( opts ); + needToSave = True; continue; if( ref_fieldset[ "identity" ] != self.nodeDarknetIdentity ): log("***"); log("*** ERROR: The bot advertised darknet ref's identity does not match the node's darknet identity; perhaps your FCP host/port setting is wrong?"); log("***"); self.setup_refurl( opts ); + needToSave = True; continue; if( ref_fieldset[ "identity" ] == self.nodeOpennetIdentity ): log("***"); log("*** ERROR: The bot advertised darknet ref's identity matches the node's opennet identity; perhaps you've got your ref URLs mixed up?"); log("***"); self.setup_refurl( opts ); + needToSave = True; continue; log("Test adding advertised darknet ref..."); try: @@ -595,12 +603,14 @@ log("*** ERROR: The node had trouble parsing the bot advertised darknet ref"); log("***"); self.setup_refurl( opts ); + needToSave = True; continue; elif( 27 == msg.info[ 'Code' ] ): log("***"); log("*** ERROR: The node could not verify the signature of the bot advertised darknet ref"); log("***"); self.setup_refurl( opts ); + needToSave = True; continue; elif( 28 == msg.info[ 'Code' ] ): log("The bot advertised darknet ref appears to be good"); @@ -629,7 +639,7 @@ break; # Testing advertised opennet ref URL - log("DEBUG: self.opennet_trades_enabled: %s" % ( self.opennet_trades_enabled )); + #log("DEBUG: self.opennet_trades_enabled: %s" % ( self.opennet_trades_enabled )); while( 'y' != opts['bot2bot_trades_only'] and self.opennet_trades_enabled ): ( url_scheme, url_netloc, url_path, url_parms, url_query, url_fragid ) = urlparse.urlparse( opts['opennet_refurl'] ); url_host = url_netloc; @@ -643,6 +653,7 @@ log("*** ERROR: The bot advertised opennet ref URL points to an RFC1918 private IP address or an unassigned bogon IP address and cannot be used on the Internet."); log("***"); self.setup_opennet_refurl( opts ); + needToSave = True; continue; log("Getting the bot advertised opennet ref from URL..."); try: @@ -657,6 +668,7 @@ log("*** ERROR: Failed to get the bot advertised opennet ref from URL."); log("***"); self.setup_opennet_refurl( opts ); + needToSave = True; continue; log("Checking syntax of advertised opennet ref..."); ref_fieldset = {}; @@ -683,13 +695,15 @@ log("***"); log("*** ERROR: The bot advertised opennet ref is really an testnet ref. The bot does not currently support testnet ref trading."); log("***"); - self.setup_refurl( opts ); + self.setup_opennet_refurl( opts ); + needToSave = True; continue; if( not ref_fieldset.has_key( "opennet" ) or ( ref_fieldset.has_key( "opennet" ) and "false" == ref_fieldset[ "opennet" ].lower() )): log("***"); log("*** ERROR: The bot advertised opennet ref is really a darknet ref; perhaps you've got your ref URLs mixed up?"); log("***"); self.setup_opennet_refurl( opts ); + needToSave = True; continue; required_ref_fields = [ "dsaGroup.g", "dsaGroup.p", "dsaGroup.q", "dsaPubKey.y", "identity", "location", "opennet", "sig" ]; for require_ref_field in required_ref_fields: @@ -700,18 +714,21 @@ ref_has_syntax_problem = True; if(ref_has_syntax_problem): self.setup_opennet_refurl( opts ); + needToSave = True; continue; if( ref_fieldset[ "identity" ] != self.nodeOpennetIdentity ): log("***"); log("*** ERROR: The bot advertised opennet ref's identity does not match the node's opennet identity; perhaps your FCP host/port setting is wrong?"); log("***"); self.setup_opennet_refurl( opts ); + needToSave = True; continue; if( ref_fieldset[ "identity" ] == self.nodeDarknetIdentity ): log("***"); log("*** ERROR: The bot advertised opennet ref's identity matches the node's darknet identity; perhaps you've got your ref URLs mixed up?"); log("***"); self.setup_opennet_refurl( opts ); + needToSave = True; continue; log("Test adding advertised opennet ref..."); try: @@ -722,12 +739,14 @@ log("*** ERROR: The node had trouble parsing the bot advertised opennet ref"); log("***"); self.setup_opennet_refurl( opts ); + needToSave = True; continue; elif( 27 == msg.info[ 'Code' ] ): log("***"); log("*** ERROR: The node could not verify the signature of the bot advertised opennet ref"); log("***"); self.setup_opennet_refurl( opts ); + needToSave = True; continue; elif( 28 == msg.info[ 'Code' ] ): log("The bot advertised opennet ref appears to be good"); @@ -757,6 +776,9 @@ f.shutdown() + if needToSave: + self.save() + self.nrefs = 0 log("Getting Peer Update...") From zothar at freenetproject.org Wed Jul 18 23:02:42 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Wed, 18 Jul 2007 23:02:42 +0000 (UTC) Subject: [Pyfreenet] r14182 - trunk/apps/pyFreenet Message-ID: <20070718230242.B8EBD47A6B9@freenetproject.org> Author: zothar Date: 2007-07-18 23:02:42 +0000 (Wed, 18 Jul 2007) New Revision: 14182 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: make sure that the bot's own idea of the current refurl is updated, rather than just the configuration, so that the updated URL gets saved. Unfortunately, there are some inconsistencies with how the configuration saving is handled, so eventually I should migrate things to the better way. Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2007-07-18 22:56:51 UTC (rev 14181) +++ trunk/apps/pyFreenet/refbot.py 2007-07-18 23:02:42 UTC (rev 14182) @@ -777,6 +777,8 @@ f.shutdown() if needToSave: + self.refurl = opts['refurl'] + self.opennet_refurl = opts['opennet_refurl'] self.save() self.nrefs = 0 From zothar at freenetproject.org Wed Jul 18 23:06:00 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Wed, 18 Jul 2007 23:06:00 +0000 (UTC) Subject: [Pyfreenet] r14183 - trunk/apps/pyFreenet Message-ID: <20070718230600.CF28347AA29@freenetproject.org> Author: zothar Date: 2007-07-18 23:06:00 +0000 (Wed, 18 Jul 2007) New Revision: 14183 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: oops, trying to supply a variable where we didn't use it Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2007-07-18 23:02:42 UTC (rev 14182) +++ trunk/apps/pyFreenet/refbot.py 2007-07-18 23:06:00 UTC (rev 14183) @@ -1281,7 +1281,7 @@ self.privmsg( self.channel, "Hi, I'm %s's noderef swap bot. I'm configured to only trade refs with humans via private message (requires registering with nickserv, i.e. /ns register ) and will not trade with bots. To swap a ref with me, /msg me with your ref url (%d ref%s to go)" \ - % ( self.nodenick, dark_open_str, refs_to_go, refs_plural_str ) + % ( self.nodenick, refs_to_go, refs_plural_str ) ) else: if( self.bot2bot_trades_enabled ): From zothar at freenetproject.org Wed Jul 18 23:21:39 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Wed, 18 Jul 2007 23:21:39 +0000 (UTC) Subject: [Pyfreenet] r14184 - trunk/apps/pyFreenet Message-ID: <20070718232139.1598247993C@freenetproject.org> Author: zothar Date: 2007-07-18 23:21:38 +0000 (Wed, 18 Jul 2007) New Revision: 14184 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: fix some bugs causing the darknet-only/opennet-only configuration to not be saved correctly. Also, correct the backwards fix committed in r14183 Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2007-07-18 23:06:00 UTC (rev 14183) +++ trunk/apps/pyFreenet/refbot.py 2007-07-18 23:21:38 UTC (rev 14184) @@ -1086,11 +1086,11 @@ if(self.darknet_trades_only_configured): f.write(fmt % ("darknet_trades_only", repr('y'))) else: - f.write(fmt % ("darknet_only", repr('n'))) + f.write(fmt % ("darknet_trades_only", repr('n'))) if(self.opennet_trades_only_configured): f.write(fmt % ("opennet_trades_only", repr('y'))) else: - f.write(fmt % ("opennet_only", repr('n'))) + f.write(fmt % ("opennet_traes_only", repr('n'))) f.close() @@ -1262,7 +1262,7 @@ dark_open_str = "darknet and opennet"; if( self.darknet_trades_only_enabled ): dark_open_str = "darknet"; - elif( self.darknet_trades_only_enabled ): + elif( self.opennet_trades_only_enabled ): dark_open_str = "opennet"; if( self.bot2bot_trades_only_enabled ): self.privmsg( @@ -1280,8 +1280,8 @@ else: self.privmsg( self.channel, - "Hi, I'm %s's noderef swap bot. I'm configured to only trade refs with humans via private message (requires registering with nickserv, i.e. /ns register ) and will not trade with bots. To swap a ref with me, /msg me with your ref url (%d ref%s to go)" \ - % ( self.nodenick, refs_to_go, refs_plural_str ) + "Hi, I'm %s's noderef swap bot. I'm configured to only trade %s refs with humans via private message (requires registering with nickserv, i.e. /ns register ) and will not trade with bots. To swap a ref with me, /msg me with your ref url (%d ref%s to go)" \ + % ( self.nodenick, dark_open_str, refs_to_go, refs_plural_str ) ) else: if( self.bot2bot_trades_enabled ): @@ -2172,7 +2172,7 @@ dark_open_str = "darknet and opennet"; if( self.darknet_trades_only_enabled ): dark_open_str = "darknet"; - elif( self.darknet_trades_only_enabled ): + elif( self.opennet_trades_only_enabled ): dark_open_str = "opennet"; self.privmsg( "I am a bot for exchanging freenet %s node references (refs)" % ( dark_open_str ), From zothar at freenetproject.org Wed Jul 18 23:32:24 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Wed, 18 Jul 2007 23:32:24 +0000 (UTC) Subject: [Pyfreenet] r14185 - trunk/apps/pyFreenet Message-ID: <20070718233224.2566147A1E7@freenetproject.org> Author: zothar Date: 2007-07-18 23:32:23 +0000 (Wed, 18 Jul 2007) New Revision: 14185 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: check for darknet-only and opennet-only being true at the same time Modified: tru