From caco_patane at freenetproject.org Fri Nov 3 01:08:25 2006 From: caco_patane at freenetproject.org (caco_patane at freenetproject.org) Date: Fri, 3 Nov 2006 01:08:25 +0000 (UTC) Subject: [Pyfreenet] r10799 - trunk/apps/pyFreenet/fcp Message-ID: <20061103010825.6448120AFAC@emu.freenetproject.org> Author: caco_patane Date: 2006-11-03 01:07:56 +0000 (Fri, 03 Nov 2006) New Revision: 10799 Modified: trunk/apps/pyFreenet/fcp/node.py Log: Added support for GetNode client-to-node FCP message and NodeData node-to-client FCP message. Modified: trunk/apps/pyFreenet/fcp/node.py =================================================================== --- trunk/apps/pyFreenet/fcp/node.py 2006-11-02 22:02:57 UTC (rev 10798) +++ trunk/apps/pyFreenet/fcp/node.py 2006-11-03 01:07:56 UTC (rev 10799) @@ -1113,6 +1113,27 @@ """ return self._submitCmd("__global", "ListPeers", **kw) + + def refstats(self, **kw): + """ + Gets node reference and possibly node statistics. + + 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 + - WithMetadata - default False - if True, returns a peer's metadata + - WithVolatile - default False - if True, returns a peer's volatile info + """ + + return self._submitCmd("__global", "GetNode", **kw) #@-node:listpeers #@+node:addpeer @@ -1984,6 +2005,17 @@ job._putResult(job.msgs) return + # ----------------------------- + # handle NodeData + if hdr == 'NodeData': + # return all the data recieved + job.callback('successful', msg) + job._putResult(msg) + + # remove job from queue + self.jobs.pop(id, None) + return + # ----------------------------- # handle various errors From zothar at freenetproject.org Fri Nov 3 13:43:26 2006 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Fri, 3 Nov 2006 13:43:26 +0000 (UTC) Subject: [Pyfreenet] r10806 - in trunk/apps/pyFreenet: . fcp Message-ID: <20061103134326.3143220AFAA@emu.freenetproject.org> Author: zothar Date: 2006-11-03 13:43:22 +0000 (Fri, 03 Nov 2006) New Revision: 10806 Modified: trunk/apps/pyFreenet/fcp/node.py trunk/apps/pyFreenet/refbot.py Log: Documentation tweaks Modified: trunk/apps/pyFreenet/fcp/node.py =================================================================== --- trunk/apps/pyFreenet/fcp/node.py 2006-11-03 13:36:56 UTC (rev 10805) +++ trunk/apps/pyFreenet/fcp/node.py 2006-11-03 13:43:22 UTC (rev 10806) @@ -1129,8 +1129,8 @@ returned from the command - if status is 'failed' or 'pending', this will contain a dict containing the response from node - - WithMetadata - default False - if True, returns a peer's metadata - - WithVolatile - default False - if True, returns a peer's volatile info + - WithPrivate - default False - if True, includes the node's private node reference fields + - WithVolatile - default False - if True, returns a node's volatile info """ return self._submitCmd("__global", "GetNode", **kw) Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2006-11-03 13:36:56 UTC (rev 10805) +++ trunk/apps/pyFreenet/refbot.py 2006-11-03 13:43:22 UTC (rev 10806) @@ -295,7 +295,7 @@ """ self.action( self.channel, - "is a Freenet NodeRef Swap-bot (www.freenet.org.nz/pyfcp/)" + "is a Freenet NodeRef Swap-bot (www.freenet.org.nz/pyfcp/ + latest SVN refbot.py and minibot.py)" ) if(self.spam_interval > 0): self.after(self.spam_interval, self.spamChannel) From nextgens at freenetproject.org Sun Nov 5 19:37:29 2006 From: nextgens at freenetproject.org (nextgens at freenetproject.org) Date: Sun, 5 Nov 2006 19:37:29 +0000 (UTC) Subject: [Pyfreenet] r10828 - trunk/apps/pyFreenet Message-ID: <20061105193729.E36579C9F9@emu.freenetproject.org> Author: nextgens Date: 2006-11-05 19:37:17 +0000 (Sun, 05 Nov 2006) New Revision: 10828 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: strip() urls Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2006-11-05 19:20:01 UTC (rev 10827) +++ trunk/apps/pyFreenet/refbot.py 2006-11-05 19:37:17 UTC (rev 10828) @@ -455,7 +455,7 @@ """ if cmd.startswith("http://"): if(not self.bot.has_ref(cmd)): - self.bot.maybe_add_ref(cmd, replyfunc) + self.bot.maybe_add_ref(cmd.strip(), replyfunc) else: self.privmsg("error - already have your ref <%s>" % (cmd)) return True @@ -518,7 +518,7 @@ url = args[0] if(not self.bot.has_ref(url)): - self.bot.maybe_add_ref(url, replyfunc) + self.bot.maybe_add_ref(url.strip(), replyfunc) else: self.privmsg("error - already have your ref <%s>"% (url)) From zothar at freenetproject.org Fri Nov 17 04:49:26 2006 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Fri, 17 Nov 2006 04:49:26 +0000 (UTC) Subject: [Pyfreenet] r10966 - trunk/apps/pyFreenet/fcp Message-ID: <20061117044926.705239CA0E@emu.freenetproject.org> Author: zothar Date: 2006-11-17 04:49:24 +0000 (Fri, 17 Nov 2006) New Revision: 10966 Modified: trunk/apps/pyFreenet/fcp/node.py Log: Now remember some of the things the node told us a NodeData time. Added FCPNode.listpeernotes() and FCPNode.modifypeernote() Modified: trunk/apps/pyFreenet/fcp/node.py =================================================================== --- trunk/apps/pyFreenet/fcp/node.py 2006-11-17 03:52:23 UTC (rev 10965) +++ trunk/apps/pyFreenet/fcp/node.py 2006-11-17 04:49:24 UTC (rev 10966) @@ -120,6 +120,9 @@ DEBUG = 6 NOISY = 7 +# peer note types +PEER_NOTE_PRIVATE_DARKNET_COMMENT = 1 + defaultVerbosity = ERROR ONE_YEAR = 86400 * 365 @@ -183,6 +186,14 @@ nodeIsAlive = False + nodeVersion = None; + nodeFCPVersion = None; + nodeBuild = None; + nodeRevision = None; + nodeExtBuild = None; + nodeExtRevision = None; + nodeIsTestnet = None; + #@-node:attribs #@+node:__init__ def __init__(self, **kw): @@ -215,6 +226,10 @@ them in the self.persistentJobs dict """ + # Be sure that we have all of our attributes during __init__ + self.running = False + self.nodeIsAlive = False + # grab and save parms env = os.environ self.name = kw.get('name', self._getUniqueId()) @@ -1114,6 +1129,30 @@ return self._submitCmd("__global", "ListPeers", **kw) + #@-node:listpeers + #@+node:listpeernotes + def listpeernotes(self, **kw): + """ + Gets the list of peer notes for a given peer from the node + + 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, identity or IP:port for the desired peer + """ + + return self._submitCmd("__global", "ListPeerNotes", **kw) + + #@-node:listpeernotes + #@+node:refstats def refstats(self, **kw): """ Gets node reference and possibly node statistics. @@ -1135,7 +1174,7 @@ return self._submitCmd("__global", "GetNode", **kw) - #@-node:listpeers + #@-node:refstats #@+node:addpeer def addpeer(self, **kw): """ @@ -1154,7 +1193,7 @@ a dict containing the response from node - File - filepath of a file containing a noderef in the node's directory - URL - URL of a copy of a peer's noderef to add - - - If neither File nor URL are provided, the fields of a raw ref are used to add a peer to the node + - - If neither File nor URL are provided, the fields of a raw ref are used to add a peer to the node (wishful thinking, don't think it can work because of the dotted subparts system that node refs use and Python probably not liking that for method argument names; will have to add raw ref string to fieldset support to make this work as a non-URL/non-file direct ref passing method -Zothar 2006/11/11) """ return self._submitCmd("__global", "AddPeer", **kw) @@ -1184,6 +1223,30 @@ return self._submitCmd("__global", "ModifyPeer", **kw) #@-node:modifypeer + #@+node:modifypeernote + def modifypeernote(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, identity or IP:port for the desired peer + - NoteText - base64 encoded string of the desired peer note text + - PeerNoteType - code number of peer note type: currently only private peer note is supported by the node with code number 1 + """ + + return self._submitCmd("__global", "ModifyPeerNote", **kw) + + #@-node:modifypeernote #@+node:removepeer def removepeer(self, **kw): """ @@ -1959,6 +2022,12 @@ # ----------------------------- # handle peer management messages + + if hdr == 'EndListPeers': + job._appendMsg(msg) + job.callback('successful', job.msgs) + job._putResult(job.msgs) + return if hdr == 'Peer': if(job.cmd == "ListPeers"): @@ -1969,17 +2038,41 @@ job._putResult(msg) return - if hdr == 'EndListPeers': + if hdr == 'PeerRemoved': job._appendMsg(msg) job.callback('successful', job.msgs) job._putResult(job.msgs) return - if hdr == 'PeerRemoved': + if hdr == 'UnknownNodeIdentifier': job._appendMsg(msg) + job.callback('failed', job.msgs) + job._putResult(job.msgs) + return + + # ----------------------------- + # handle peer note management messages + + if hdr == 'EndListPeerNotes': + job._appendMsg(msg) job.callback('successful', job.msgs) job._putResult(job.msgs) return + + if hdr == 'PeerNote': + if(job.cmd == "ListPeerNotes"): + job.callback('pending', msg) + job._appendMsg(msg) + else: + job.callback('successful', msg) + job._putResult(msg) + return + + if hdr == 'UnknownPeerNoteType': + job._appendMsg(msg) + job.callback('failed', job.msgs) + job._putResult(job.msgs) + return # ----------------------------- # handle persistent job messages @@ -2005,10 +2098,10 @@ job._putResult(job.msgs) return - # ----------------------------- - # handle NodeData - if hdr == 'NodeData': - # return all the data recieved + # ----------------------------- + # handle NodeData + if hdr == 'NodeData': + # return all the data recieved job.callback('successful', msg) job._putResult(msg) @@ -2055,6 +2148,42 @@ ExpectedVersion=expectedVersion) resp = self._rxMsg() + if(resp.has_key("Version")): + self.nodeVersion = resp[ "Version" ]; + if(resp.has_key("FCPVersion")): + self.nodeFCPVersion = resp[ "FCPVersion" ]; + if(resp.has_key("Build")): + try: + self.nodeBuild = int( resp[ "Build" ] ); + except Exception, msg: + pass; + else: + nodeVersionFields = self.nodeVersion.split( "," ); + if( len( nodeVersionFields ) == 4 ): + try: + self.nodeBuild = int( nodeVersionFields[ 3 ] ); + except Exception, msg: + pass; + if(resp.has_key("Revision")): + try: + self.nodeRevision = int( resp[ "Revision" ] ); + except Exception, msg: + pass; + if(resp.has_key("ExtBuild")): + try: + self.nodeExtBuild = int( resp[ "ExtBuild" ] ); + except Exception, msg: + pass; + if(resp.has_key("Revision")): + try: + self.nodeExtRevision = int( resp[ "ExtRevision" ] ); + except Exception, msg: + pass; + if(resp.has_key("Testnet")): + if( "true" == resp[ "Testnet" ] ): + self.nodeIsTestnet = True; + else: + self.nodeIsTestnet = False; return resp #@-node:_hello From zothar at freenetproject.org Fri Nov 17 05:00:49 2006 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Fri, 17 Nov 2006 05:00:49 +0000 (UTC) Subject: [Pyfreenet] r10967 - trunk/apps/pyFreenet Message-ID: <20061117050049.98C9D9C9F2@emu.freenetproject.org> Author: zothar Date: 2006-11-17 05:00:47 +0000 (Fri, 17 Nov 2006) New Revision: 10967 Modified: trunk/apps/pyFreenet/refbot.py Log: Check a noderef's identity against the node for duplication before adding. Add a private peer note with some basic information about the peer add after adding the peer. Add FCP host and port to configuration. Require a minimum build for the node. Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2006-11-17 04:49:24 UTC (rev 10966) +++ trunk/apps/pyFreenet/refbot.py 2006-11-17 05:00:47 UTC (rev 10967) @@ -7,12 +7,15 @@ """ #@+others #@+node:imports +import base64 +import StringIO import sys, time, traceback, time import socket, select import threading import os #not necassary but later on I am going to use a few features from this import urllib2 +import fcp from minibot import log, MiniBot, PrivateChat #@-node:imports @@ -61,6 +64,7 @@ svnLongRevision = "$Revision$" svnRevision = svnLongRevision[ 11 : -2 ] + minimumNodeBuild = 998; #@ @+others #@+node:__init__ @@ -112,6 +116,16 @@ else: self.chan = "#freenet-refs" needToSave = True + if(opts.has_key('fcp_host')): + self.fcp_host = opts['fcp_host'] + else: + self.fcp_host = "127.0.0.1"; + needToSave = True + if(opts.has_key('fcp_port')): + self.fcp_port = opts['fcp_port'] + else: + self.fcp_port = 9481; + needToSave = True if(opts.has_key('greetinterval')): self.greet_interval = opts['greetinterval'] else: @@ -128,9 +142,39 @@ self.number_of_refs_to_collect = 10 needToSave = True self.refs = opts['refs'] - self.telnethost = opts['telnethost'] - self.telnetport = opts['telnetport'] + if(opts.has_key('telnethost')): + self.tmci_host = opts['telnethost'] + needToSave = True + else: + if(opts.has_key('tmci_host')): + self.tmci_host = opts['tmci_host'] + else: + self.tmci_host = "127.0.0.1"; + needToSave = True + if(opts.has_key('telnetport')): + self.tmci_port = opts['telnetport'] + needToSave = True + else: + if(opts.has_key('tmci_port')): + self.tmci_port = opts['tmci_port'] + else: + self.tmci_port = 2323; + needToSave = True self.refurl = opts['refurl'] + + # for internal use shadow of MiniBot configs + self.irc_host = kw[ 'host' ] + self.irc_port = kw[ 'port' ] + + try: + f = fcp.FCPNode( host = self.fcp_host, port = self.fcp_port ) + f.shutdown() + except Exception, msg: + print "Failed to connect to node via FCP. Check your fcp host and port settings on both the node and the bot config." + sys.exit( 1 ); + if( f.nodeBuild < self.minimumNodeBuild ): + print "This version of the refbot requires your node be running build %d or higher. Please upgrade your Freenet node and try again." % ( self.minimumNodeBuild ); + sys.exit( 1 ); # finally construct the parent MiniBot.__init__(self, **kw) @@ -183,16 +227,26 @@ except: print "Invalid port '%s'" % opts['ircport'] - opts['telnethost'] = prompt("Node Telnet hostname", "127.0.0.1") + opts['tmci_host'] = prompt("Node TMCI (telnet) hostname", "127.0.0.1") while 1: - opts['telnetport'] = prompt("Node Telnet port", "2323") + opts['tmci_port'] = prompt("Node TMCI (telnet) port", "2323") try: - opts['telnetport'] = int(opts['telnetport']) + opts['tmci_port'] = int(opts['tmci_port']) break except: - print "Invalid port '%s'" % opts['telnetport'] + print "Invalid port '%s'" % opts['tmci_port'] + opts['fcp_host'] = prompt("Node FCP hostname", "127.0.0.1") + + while 1: + opts['fcp_port'] = prompt("Node FCP port", "2323") + try: + opts['fcp_port'] = int(opts['fcp_port']) + break + except: + print "Invalid port '%s'" % opts['fcp_port'] + opts['greetinterval'] = 1200 opts['spaminterval'] = 3600 opts['refsperrun'] = 10 @@ -212,8 +266,10 @@ f.write(fmt % ("usernick", repr(self.nodenick))) f.write(fmt % ("irchost", repr(self.host))) f.write(fmt % ("ircport", repr(self.port))) - f.write(fmt % ("telnethost", repr(self.telnethost))) - f.write(fmt % ("telnetport", repr(self.telnetport))) + f.write(fmt % ("tmci_host", repr(self.tmci_host))) + f.write(fmt % ("tmci_port", repr(self.tmci_port))) + 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 % ("password", repr(self.password))) f.write(fmt % ("greetinterval", repr(self.greet_interval))) @@ -295,7 +351,7 @@ """ self.action( self.channel, - "is a Freenet NodeRef Swap-bot (www.freenet.org.nz/pyfcp/ + latest SVN refbot.py and minibot.py)" + "is a Freenet NodeRef Swap-bot (www.freenet.org.nz/pyfcp/ + latest SVN refbot.py minibot.py and fcp/node.py)" ) if(self.spam_interval > 0): self.after(self.spam_interval, self.spamChannel) @@ -320,10 +376,10 @@ #@-node:thankChannelThenDie #@+node:addref - def addref(self, url, replyfunc): + def addref(self, url, replyfunc, sender_irc_nick): log("** adding ref: %s" % url) - adderThread = AddRef(self.telnethost, self.telnetport, url, replyfunc) + adderThread = AddRef(self.tmci_host, self.tmci_port, self.fcp_host, self.fcp_port, url, replyfunc, sender_irc_nick, self.irc_host) self.adderThreads.append(adderThread) adderThread.start() @@ -361,7 +417,9 @@ elif(-2 == adderThread.status): error_str = "there was a problem fetching the given URL. Please correct the URL <%s> and try again, or try again later if you suspect server troubles." % (adderThread.url) elif(-3 == adderThread.status): - error_str = "there was a problem talking to the node. Please try again later." % (adderThread.url) + error_str = "there was a problem talking to the node. Please try again later." + elif(-4 == adderThread.status): + error_str = "the node reports that it already has a peer with that identity. Ref not re-added." refs_to_go = self.number_of_refs_to_collect - self.nrefs refs_to_go_str = '' if refs_to_go > 0: @@ -405,12 +463,12 @@ return False #@-node:has_ref #@+node:maybe_add_ref - def maybe_add_ref(self, url, replyfunc): + def maybe_add_ref(self, url, replyfunc, sender_irc_nick): """ Checks, adds and replies to a ref add request """ if( self.check_ref_url_and_complain(url, replyfunc)): - self.addref(url,replyfunc) + self.addref(url, replyfunc, sender_irc_nick) #@-node:maybe_add_ref #@-others @@ -455,7 +513,7 @@ """ if cmd.startswith("http://"): if(not self.bot.has_ref(cmd)): - self.bot.maybe_add_ref(cmd.strip(), replyfunc) + self.bot.maybe_add_ref(cmd.strip(), replyfunc, self.peernick) else: self.privmsg("error - already have your ref <%s>" % (cmd)) return True @@ -518,7 +576,7 @@ url = args[0] if(not self.bot.has_ref(url)): - self.bot.maybe_add_ref(url.strip(), replyfunc) + self.bot.maybe_add_ref(url.strip(), replyfunc, self.peernick) else: self.privmsg("error - already have your ref <%s>"% (url)) @@ -537,20 +595,27 @@ #@-node:class RefBotConversation #@+node:class AddRef class AddRef(threading.Thread): - def __init__(self, host, port, url, replyfunc): + def __init__(self, tmci_host, tmci_port, fcp_host, fcp_port, url, replyfunc, sender_irc_nick, irc_host): threading.Thread.__init__(self) - self.host = host - self.port = port + self.tmci_host = tmci_host + self.tmci_port = tmci_port + self.fcp_host = fcp_host + self.fcp_port = fcp_port self.url = url self.replyfunc = replyfunc + self.sender_irc_nick = sender_irc_nick + self.irc_host = irc_host self.status = 0 self.error_msg = None def run(self): try: openurl = urllib2.urlopen(self.url) - reflines = openurl.readlines(); - openurl.close(); + refbuf = openurl.read(20*1024) # read up to 20 KiB + openurl.close() + refmemfile = StringIO.StringIO(refbuf) + reflines = refmemfile.readlines() + refmemfile.close(); except Exception, msg: self.status = -2 self.error_msg = msg @@ -573,10 +638,22 @@ self.status = -1 # invalid ref found at URL self.error_msg = "No identity field in ref" return + if(not ref_fieldset.has_key("myName")): + self.status = -1 # invalid ref found at URL + self.error_msg = "No myName field in ref" + return try: + f = fcp.FCPNode( host = self.fcp_host, port = self.fcp_port ) + returned_peer = f.modifypeer( NodeIdentifier = ref_fieldset[ "identity" ] ) + if( type( returned_peer ) == type( [] )): + returned_peer = returned_peer[ 0 ]; + if( returned_peer[ "header" ] == "Peer" ): + self.status = -4 + self.error_msg = "Node already has a peer with that identity" + return sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - sock.connect((self.host, self.port)) + sock.connect((self.tmci_host, self.tmci_port)) # wait for something to come in sock.recv(1) @@ -608,6 +685,14 @@ self.error_msg = msg return + try: + 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() ) ) + 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(not ref_fieldset.has_key("physical.udp")): self.status = 2 self.error_msg = "No physical.udp field in ref" From zothar at freenetproject.org Mon Nov 20 03:30:15 2006 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Mon, 20 Nov 2006 03:30:15 +0000 (UTC) Subject: [Pyfreenet] r11016 - trunk/apps/pyFreenet Message-ID: <20061120033015.D5AA29BBB5@emu.freenetproject.org> Author: zothar Date: 2006-11-20 03:30:12 +0000 (Mon, 20 Nov 2006) New Revision: 11016 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: Write the config before possibly bailing with a complaint that we couldn't connect to the node via FCP (mention the host and port in the complaint). This way, the new fields will be in the config file for the user to edit when instructed to check their settings. Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2006-11-19 22:18:40 UTC (rev 11015) +++ trunk/apps/pyFreenet/refbot.py 2006-11-20 03:30:12 UTC (rev 11016) @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python2.4 #@+leo-ver=4 #@+node:@file refbot.py #@@first @@ -165,12 +165,15 @@ # for internal use shadow of MiniBot configs self.irc_host = kw[ 'host' ] self.irc_port = kw[ 'port' ] + + if needToSave: + self.save() try: f = fcp.FCPNode( host = self.fcp_host, port = self.fcp_port ) f.shutdown() except Exception, msg: - print "Failed to connect to node via FCP. Check your fcp host and port settings on both the node and the bot config." + print "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 ); sys.exit( 1 ); if( f.nodeBuild < self.minimumNodeBuild ): print "This version of the refbot requires your node be running build %d or higher. Please upgrade your Freenet node and try again." % ( self.minimumNodeBuild ); From zothar at freenetproject.org Mon Nov 20 23:51:24 2006 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Mon, 20 Nov 2006 23:51:24 +0000 (UTC) Subject: [Pyfreenet] r11027 - trunk/apps/pyFreenet Message-ID: <20061120235124.AED309CA0F@emu.freenetproject.org> Author: zothar Date: 2006-11-20 23:51:22 +0000 (Mon, 20 Nov 2006) New Revision: 11027 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: Save only after calling MiniBot.__init__(). Fix the default port number for FCP. Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2006-11-20 20:44:07 UTC (rev 11026) +++ trunk/apps/pyFreenet/refbot.py 2006-11-20 23:51:22 UTC (rev 11027) @@ -166,6 +166,9 @@ self.irc_host = kw[ 'host' ] self.irc_port = kw[ 'port' ] + # finally construct the parent + MiniBot.__init__(self, **kw) + if needToSave: self.save() @@ -179,12 +182,6 @@ print "This version of the refbot requires your node be running build %d or higher. Please upgrade your Freenet node and try again." % ( self.minimumNodeBuild ); sys.exit( 1 ); - # finally construct the parent - MiniBot.__init__(self, **kw) - - if needToSave: - self.save() - self.timeLastChanGreeting = time.time() self.haveSentDownloadLink = False @@ -243,7 +240,7 @@ opts['fcp_host'] = prompt("Node FCP hostname", "127.0.0.1") while 1: - opts['fcp_port'] = prompt("Node FCP port", "2323") + opts['fcp_port'] = prompt("Node FCP port", "9481") try: opts['fcp_port'] = int(opts['fcp_port']) break From zothar at freenetproject.org Fri Nov 24 15:21:26 2006 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Fri, 24 Nov 2006 15:21:26 +0000 (UTC) Subject: [Pyfreenet] r11040 - trunk/apps/pyFreenet Message-ID: <20061124152126.A3CA49C9CD@emu.freenetproject.org> Author: zothar Date: 2006-11-24 15:21:23 +0000 (Fri, 24 Nov 2006) New Revision: 11040 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: bot won't try to add its node's own ref Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2006-11-24 00:20:24 UTC (rev 11039) +++ trunk/apps/pyFreenet/refbot.py 2006-11-24 15:21:23 UTC (rev 11040) @@ -420,6 +420,8 @@ error_str = "there was a problem talking to the node. Please try again later." elif(-4 == adderThread.status): error_str = "the node reports that it already has a peer with that identity. Ref not re-added." + elif(-5 == adderThread.status): + error_str = "the node reports that it already has a ref with its own identity. Ref not added." refs_to_go = self.number_of_refs_to_collect - self.nrefs refs_to_go_str = '' if refs_to_go > 0: @@ -512,6 +514,9 @@ Pick up possible URLs """ if cmd.startswith("http://"): + if(cmd == self.bot.refurl): + self.privmsg("error - already have my own ref <%s>" % (cmd)) + return True if(not self.bot.has_ref(cmd)): self.bot.maybe_add_ref(cmd.strip(), replyfunc, self.peernick) else: @@ -575,6 +580,9 @@ return url = args[0] + if(cmd == self.bot.refurl): + self.privmsg("error - already have my own ref <%s>" % (cmd)) + return if(not self.bot.has_ref(url)): self.bot.maybe_add_ref(url.strip(), replyfunc, self.peernick) else: @@ -645,6 +653,14 @@ try: f = fcp.FCPNode( host = self.fcp_host, port = self.fcp_port ) + noderef = f.refstats(); + if( type( noderef ) == type( [] )): + noderef = noderef[ 0 ]; + if( noderef[ "identity" ] == ref_fieldset[ "identity" ] ): + self.status = -5 + self.error_msg = "Node already has a ref with its own identity" + return + print "DEBUG: noderef: [%s]" % ( noderef ); returned_peer = f.modifypeer( NodeIdentifier = ref_fieldset[ "identity" ] ) if( type( returned_peer ) == type( [] )): returned_peer = returned_peer[ 0 ]; From zothar at freenetproject.org Fri Nov 24 19:37:00 2006 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Fri, 24 Nov 2006 19:37:00 +0000 (UTC) Subject: [Pyfreenet] r11041 - trunk/apps/pyFreenet Message-ID: <20061124193700.B3FB99CA90@emu.freenetproject.org> Author: zothar Date: 2006-11-24 19:36:57 +0000 (Fri, 24 Nov 2006) New Revision: 11041 Added: trunk/apps/pyFreenet/botplugin.py.dist Modified: trunk/apps/pyFreenet/refbot.py Log: refbot.py can now use a pre-add and post-add plugin. Also, it closes the FCP connection more cleanly. Added: trunk/apps/pyFreenet/botplugin.py.dist =================================================================== --- trunk/apps/pyFreenet/botplugin.py.dist 2006-11-24 15:21:23 UTC (rev 11040) +++ trunk/apps/pyFreenet/botplugin.py.dist 2006-11-24 19:36:57 UTC (rev 11041) @@ -0,0 +1,24 @@ +# +# +# This file is not to be run directly, but used by refbot.py +# Rename it to botplugin.py to be used by refbot.py +# Add/modify code in the this file to add appropriate +# functionality +# + +def botplugin_log( logline ): + print "botplugin_log: %s" % ( logline ); + +def pre_add( argsdict ): + log = botplugin_log; + if( argsdict.has_key( "log_function" )): + log = argsdict[ "log_function" ]; + log("DEBUG: botplugin.pre_add() here" ); + return None; + +def post_add( argsdict ): + log = botplugin_log; + if( argsdict.has_key( "log_function" )): + log = argsdict[ "log_function" ]; + log("DEBUG: botplugin.post_add() here" ); + return None; Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2006-11-24 15:21:23 UTC (rev 11040) +++ trunk/apps/pyFreenet/refbot.py 2006-11-24 19:36:57 UTC (rev 11041) @@ -18,6 +18,13 @@ import fcp from minibot import log, MiniBot, PrivateChat +have_plugin_module = False; +try: + import botplugin; + have_plugin_module = True; +except Exception, msg: + pass; + #@-node:imports #@+node:globals progname = sys.argv[0] @@ -422,6 +429,8 @@ error_str = "the node reports that it already has a peer with that identity. Ref not re-added." elif(-5 == adderThread.status): error_str = "the node reports that it already has a ref with its own identity. Ref not added." + elif(-6 == adderThread.status): + error_str = adderThread.error_msg refs_to_go = self.number_of_refs_to_collect - self.nrefs refs_to_go_str = '' if refs_to_go > 0: @@ -615,6 +624,7 @@ self.irc_host = irc_host 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 }; def run(self): try: @@ -653,20 +663,34 @@ try: f = fcp.FCPNode( host = self.fcp_host, port = self.fcp_port ) + if( have_plugin_module ): + try: + self.plugin_args[ "fcpNode" ] = f; + self.plugin_args[ "ref" ] = ref_fieldset; + plugin_result = botplugin.pre_add( self.plugin_args ); + if( plugin_result != None ): + log("DEBUG: pre_add plugin rejected ref: would fail here **FIXME**: %s" % ( plugin_result )); + self.status = -6 + self.error_msg = plugin_result + f.shutdown(); + return + except Exception, msg: + log("DEBUG: exception calling botplugin.pre_add(): %s" % ( msg )); noderef = f.refstats(); if( type( noderef ) == type( [] )): noderef = noderef[ 0 ]; if( noderef[ "identity" ] == ref_fieldset[ "identity" ] ): self.status = -5 self.error_msg = "Node already has a ref with its own identity" + f.shutdown(); return - print "DEBUG: noderef: [%s]" % ( noderef ); returned_peer = f.modifypeer( NodeIdentifier = ref_fieldset[ "identity" ] ) if( type( returned_peer ) == type( [] )): returned_peer = returned_peer[ 0 ]; if( returned_peer[ "header" ] == "Peer" ): self.status = -4 self.error_msg = "Node already has a peer with that identity" + f.shutdown(); return sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((self.tmci_host, self.tmci_port)) @@ -699,15 +723,23 @@ except Exception, msg: self.status = -3 self.error_msg = msg + f.shutdown(); return + if( have_plugin_module ): + try: + plugin_result = botplugin.post_add( self.plugin_args ); + except Exception, msg: + log("DEBUG: exception calling botplugin.post_add(): %s" % ( msg )); try: 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() ) ) 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 ) + f.shutdown(); 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")): self.status = 2 From zothar at freenetproject.org Sun Nov 26 23:11:08 2006 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Sun, 26 Nov 2006 23:11:08 +0000 (UTC) Subject: [Pyfreenet] r11064 - trunk/apps/pyFreenet Message-ID: <20061126231108.67BF79BCDF@emu.freenetproject.org> Author: zothar Date: 2006-11-26 23:11:05 +0000 (Sun, 26 Nov 2006) New Revision: 11064 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: Oops, didn't mean for the python version specific bit to get in there Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2006-11-26 20:31:21 UTC (rev 11063) +++ trunk/apps/pyFreenet/refbot.py 2006-11-26 23:11:05 UTC (rev 11064) @@ -1,4 +1,4 @@ -#!/usr/bin/env python2.4 +#!/usr/bin/env python #@+leo-ver=4 #@+node:@file refbot.py #@@first From zothar at freenetproject.org Mon Nov 27 02:55:05 2006 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Mon, 27 Nov 2006 02:55:05 +0000 (UTC) Subject: [Pyfreenet] r11065 - trunk/apps/pyFreenet Message-ID: <20061127025505.B17A39C9C5@emu.freenetproject.org> Author: zothar Date: 2006-11-27 02:55:02 +0000 (Mon, 27 Nov 2006) New Revision: 11065 Added: trunk/apps/pyFreenet/updater.py Log: Add the beginnings of updater.py so that it has something to self-update to Added: trunk/apps/pyFreenet/updater.py =================================================================== --- trunk/apps/pyFreenet/updater.py 2006-11-26 23:11:05 UTC (rev 11064) +++ trunk/apps/pyFreenet/updater.py 2006-11-27 02:55:02 UTC (rev 11065) @@ -0,0 +1,76 @@ +#!/usr/bin/env python +""" +Update portions of the pyfcp files, specifically the refbot related ones at the moment +""" + +import base64 +import StringIO +import sys, time, traceback, time +import socket, select +import threading +import os #not necassary but later on I am going to use a few features from this +import urllib2 + +print "Not implemented yet" +sys.exit( 1 ); + +# This file is just here so that the updater has something to self-update to while it's being developed + +base_url = "http://emu.freenetproject.org/cgi-bin/view-cvs/trunk/apps/pyFreenet/"; +files_to_update = [ + "fcp/node.py", + "refbot.py", + "minbot.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 +versions_filename = "updater_versions.dat"; + +versions_file_lines = []; +try: + versions_file = file( versions_filename, "r" ); + versions_file_lines = versions_file.readlines(); + version_file.close(); +except: + pass; # Ignore a non-existent versions_file +local_versions = {}; +for versions_file_line in versions_file_lines: + versions_file_line = version_file_line.strip(); + versions_file_line_fields = version_file_line.split(); + if( 2 != versions_file_line_fields ): + continue; + filename = versions_file_line_fields[ 1 ]; + version = versions_file_line_fields[ 1 ]; + try: + local_versions[ filename ] = int( version ); + except: + pass; # Ignore file versions we can't parse +if(not local_versions.has_key( "updater.py" )): + local_versions[ "updater.py" ] = 0; +base_url_lines = []; +updater_backup_url_lines = []; +try: + base_url_file = urllib2.urlopen(base_url); + base_url_lines = base_url_file.readlines() + base_url_file.close(); +except: + try: + updater_backup_url_file = urllib2.urlopen(updater_backup_url); + updater_backup_url_lines = updater_backup_url_file.readlines() + updater_backup_url_file.close(); + except: + print "Couldn't fetch fetch the base URL information or the updater backup URL for some reason. You may have to update the updater via other means or try again later."; + sys.exit( 1 ); +if( 0 != len( base_url_lines )): # If we could download the View CVS directory listing... + for base_url_line in base_url_lines: + base_url_line = base_url_line.strip(); + print "DEBUG: base_url_line: [%s]" % ( base_url_line ); +else: + if( 0 != len( updater_backup_url_lines )): # If we could download the updater from the backup URL + for updater_backup_url_line in updater_backup_url_lines: + updater_backup_url_line = updater_backup_url_line.rstrip(); + print "DEBUG: updater_backup_url_line: [%s]" % ( updater_backup_url_line ); + else: + print "Couldn't fetch fetch the base URL information and the updater backup URL returned no data. You may have to update the updater via other means or try again later."; + sys.exit( 1 ); +print "Not implemented yet" +sys.exit( 1 ); Property changes on: trunk/apps/pyFreenet/updater.py ___________________________________________________________________ Name: svn:executable + * From zothar at freenetproject.org Mon Nov 27 03:40:09 2006 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Mon, 27 Nov 2006 03:40:09 +0000 (UTC) Subject: [Pyfreenet] r11066 - trunk/apps/pyFreenet Message-ID: <20061127034009.569D89CA28@emu.freenetproject.org> Author: zothar Date: 2006-11-27 03:40:07 +0000 (Mon, 27 Nov 2006) New Revision: 11066 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: Fixed bug in don't add self check (found by alphaNick) Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2006-11-27 02:55:02 UTC (rev 11065) +++ trunk/apps/pyFreenet/refbot.py 2006-11-27 03:40:07 UTC (rev 11066) @@ -589,7 +589,7 @@ return url = args[0] - if(cmd == self.bot.refurl): + if(url == self.bot.refurl): self.privmsg("error - already have my own ref <%s>" % (cmd)) return if(not self.bot.has_ref(url)): From zothar at freenetproject.org Mon Nov 27 03:48:14 2006 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Mon, 27 Nov 2006 03:48:14 +0000 (UTC) Subject: [Pyfreenet] r11067 - trunk/apps/pyFreenet Message-ID: <20061127034814.4611C9CA66@emu.freenetproject.org> Author: zothar Date: 2006-11-27 03:48:11 +0000 (Mon, 27 Nov 2006) New Revision: 11067 Modified: trunk/apps/pyFreenet/updater.py Log: updater: Small msg tweak for development testing Modified: trunk/apps/pyFreenet/updater.py =================================================================== --- trunk/apps/pyFreenet/updater.py 2006-11-27 03:40:07 UTC (rev 11066) +++ trunk/apps/pyFreenet/updater.py 2006-11-27 03:48:11 UTC (rev 11067) @@ -11,7 +11,7 @@ import os #not necassary but later on I am going to use a few features from this import urllib2 -print "Not implemented yet" +print "Not implemented yet (updater.py from SVN)" sys.exit( 1 ); # This file is just here so that the updater has something to self-update to while it's being developed From zothar at freenetproject.org Mon Nov 27 03:50:27 2006 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Mon, 27 Nov 2006 03:50:27 +0000 (UTC) Subject: [Pyfreenet] r11068 - trunk/apps/pyFreenet Message-ID: <20061127035027.C1B5C9CA66@emu.freenetproject.org> Author: zothar Date: 2006-11-27 03:50:22 +0000 (Mon, 27 Nov 2006) New Revision: 11068 Modified: trunk/apps/pyFreenet/minibot.py trunk/apps/pyFreenet/refbot.py trunk/apps/pyFreenet/updater.py Log: typo Modified: trunk/apps/pyFreenet/minibot.py =================================================================== --- trunk/apps/pyFreenet/minibot.py 2006-11-27 03:48:11 UTC (rev 11067) +++ trunk/apps/pyFreenet/minibot.py 2006-11-27 03:50:22 UTC (rev 11068) @@ -11,7 +11,7 @@ import socket, select import string import thread, threading -import os #not necassary but later on I am going to use a few features from this +import os #not necessary but later on I am going to use a few features from this #@-node:imports #@+node:globals Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2006-11-27 03:48:11 UTC (rev 11067) +++ trunk/apps/pyFreenet/refbot.py 2006-11-27 03:50:22 UTC (rev 11068) @@ -12,7 +12,7 @@ import sys, time, traceback, time import socket, select import threading -import os #not necassary but later on I am going to use a few features from this +import os #not necessary but later on I am going to use a few features from this import urllib2 import fcp Modified: trunk/apps/pyFreenet/updater.py =================================================================== --- trunk/apps/pyFreenet/updater.py 2006-11-27 03:48:11 UTC (rev 11067) +++ trunk/apps/pyFreenet/updater.py 2006-11-27 03:50:22 UTC (rev 11068) @@ -8,7 +8,7 @@ import sys, time, traceback, time import socket, select import threading -import os #not necassary but later on I am going to use a few features from this +import os #not necessary but later on I am going to use a few features from this import urllib2 print "Not implemented yet (updater.py from SVN)" From zothar at freenetproject.org Mon Nov 27 05:36:13 2006 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Mon, 27 Nov 2006 05:36:13 +0000 (UTC) Subject: [Pyfreenet] r11069 - trunk/apps/pyFreenet Message-ID: <20061127053613.3A92020B0CD@emu.freenetproject.org> Author: zothar Date: 2006-11-27 05:36:08 +0000 (Mon, 27 Nov 2006) New Revision: 11069 Modified: trunk/apps/pyFreenet/updater.py Log: updater: big chunk of code, but lacking a major feature and not cleaned up from development/debugging yet. Modified: trunk/apps/pyFreenet/updater.py =================================================================== --- trunk/apps/pyFreenet/updater.py 2006-11-27 03:50:22 UTC (rev 11068) +++ trunk/apps/pyFreenet/updater.py 2006-11-27 05:36:08 UTC (rev 11069) @@ -1,76 +1,192 @@ #!/usr/bin/env python """ Update portions of the pyfcp files, specifically the refbot related ones at the moment + +This is very much tied to the current way View CVS works, which we use so we +know what SVN versions we're updating to, etc. """ -import base64 -import StringIO -import sys, time, traceback, time -import socket, select -import threading -import os #not necessary but later on I am going to use a few features from this -import urllib2 +import StringIO; +import base64; +import os; +import select; +import socket; +import sys; +import threading; +import time; +import traceback; +import urllib2; print "Not implemented yet (updater.py from SVN)" sys.exit( 1 ); -# This file is just here so that the updater has something to self-update to while it's being developed - -base_url = "http://emu.freenetproject.org/cgi-bin/view-cvs/trunk/apps/pyFreenet/"; +base_url = "http://emu.freenetproject.org/cgi-bin/viewcvs.cgi/trunk/apps/pyFreenet/"; +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/node.py", "refbot.py", - "minbot.py", + "minibot.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"; versions_filename = "updater_versions.dat"; -versions_file_lines = []; -try: - versions_file = file( versions_filename, "r" ); - versions_file_lines = versions_file.readlines(); - version_file.close(); -except: - pass; # Ignore a non-existent versions_file -local_versions = {}; -for versions_file_line in versions_file_lines: - versions_file_line = version_file_line.strip(); - versions_file_line_fields = version_file_line.split(); - if( 2 != versions_file_line_fields ): - continue; - filename = versions_file_line_fields[ 1 ]; - version = versions_file_line_fields[ 1 ]; +def download_file( download_base_url, filename, version ): + print "Downloading %s ..." % ( filename ); + download_url = "%s?rev=%d" % ( os.path.join( download_base_url, filename ), version ); + #print "download_file(): Not implemented yet: %s" % ( download_url ); + download_url_file = urllib2.urlopen(download_url); + download_url_lines = download_url_file.readlines() + download_url_file.close(); + return download_url_lines; + +def needs_update( filename, local_versions, remote_versions ): + if( not local_versions.has_key( filename )): + local_versions[ filename ] = 0; + if( remote_versions.has_key( filename )): + if( local_versions[ filename ] < remote_versions[ filename ] ): + return True; + return False; + +def process_raw_remote_versions_data( remote_versions, input_lines ): + print "Processing the base file list..."; + for input_line in input_lines: + # Yeah, this is very tied to the output of View CVS at the moment... + input_line = input_line.strip(); + if(0 == len( input_line )): + continue; + searchstr = " Author: zothar Date: 2006-11-28 02:00:30 +0000 (Tue, 28 Nov 2006) New Revision: 11080 Modified: trunk/apps/pyFreenet/updater.py Log: pyfcp: The first working pyfcp updater. Currently it should be updating the files that are needed by the latest SVN refbot. The updater will always fetch the latest version of each file from SVN. Modified: trunk/apps/pyFreenet/updater.py =================================================================== --- trunk/apps/pyFreenet/updater.py 2006-11-28 01:42:39 UTC (rev 11079) +++ trunk/apps/pyFreenet/updater.py 2006-11-28 02:00:30 UTC (rev 11080) @@ -4,6 +4,11 @@ This is very much tied to the current way View CVS works, which we use so we know what SVN versions we're updating to, etc. + +This code was written by Zothar, November 2006, released under the GNU Lesser General +Public License. + +No warranty, yada yada """ import StringIO; @@ -17,9 +22,6 @@ import traceback; import urllib2; -print "Not implemented yet (updater.py from SVN)" -sys.exit( 1 ); - base_url = "http://emu.freenetproject.org/cgi-bin/viewcvs.cgi/trunk/apps/pyFreenet/"; 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 @@ -32,15 +34,27 @@ updater_filename = "updater.py"; versions_filename = "updater_versions.dat"; +def do_revision_substitution( downloaded_file_lines, revision ): + substituted_file_lines = []; + substituted_string = "$Revision: %d $" % ( revision ); + for downloaded_file_line in downloaded_file_lines: + substituted_file_lines.append( downloaded_file_line.replace( "$Revision$", substituted_string )); + return substituted_file_lines; + def download_file( download_base_url, filename, version ): print "Downloading %s ..." % ( filename ); download_url = "%s?rev=%d" % ( os.path.join( download_base_url, filename ), version ); - #print "download_file(): Not implemented yet: %s" % ( download_url ); download_url_file = urllib2.urlopen(download_url); download_url_lines = download_url_file.readlines() download_url_file.close(); return download_url_lines; +def get_remote_versions_data( url ): + url_file = urllib2.urlopen(url); + url_lines = url_file.readlines() + url_file.close(); + return url_lines; + def needs_update( filename, local_versions, remote_versions ): if( not local_versions.has_key( filename )): local_versions[ filename ] = 0; @@ -49,10 +63,9 @@ return True; return False; -def process_raw_remote_versions_data( remote_versions, input_lines ): - print "Processing the base file list..."; +def process_raw_remote_versions_data( remote_versions, input_lines, filename_prefix ): for input_line in input_lines: - # Yeah, this is very tied to the output of View CVS at the moment... + # This is very tied to the output of View CVS... input_line = input_line.strip(); if(0 == len( input_line )): continue; @@ -61,15 +74,14 @@ i = input_line.find( searchstr ); if( -1 == i ): continue; - #print "DEBUG: input_line: [%s]" % ( input_line ); buf = input_line[ ( i + searchstrlen ) : ]; - #print " DEBUG: buf: [%s]" % ( buf ); searchstr = '"'; searchstrlen = len( searchstr ); i = buf.find( searchstr ); if( -1 == i ): continue; filename = buf[ :i ]; + filename = filename_prefix + filename; searchstr = "?rev="; searchstrlen = len( searchstr ); i = buf.find( searchstr ); @@ -81,7 +93,6 @@ i = buf.find( searchstr ); if( -1 != i ): buf = buf[ :i ]; - #print " DEBUG: buf: [%s]" % ( buf ); try: version = int( buf ); remote_versions[ filename ] = version; @@ -99,13 +110,11 @@ pass; # Ignore a non-existent versions_file for versions_file_line in versions_file_lines: versions_file_line = versions_file_line.strip(); - #print "DEBUG: versions_file_line: [%s]" % ( versions_file_line ); versions_file_line_fields = versions_file_line.split(); if( 2 != len( versions_file_line_fields )): continue; filename = versions_file_line_fields[ 1 ]; version = versions_file_line_fields[ 0 ]; - #print "DEBUG: filename: %s version: %s" % ( filename, version ); try: local_versions[ filename ] = int( version ); except: @@ -128,12 +137,13 @@ # We want to work in the directory where pyfcp is installed os.chdir( os.path.dirname( sys.argv[ 0 ] )); -# We dont' want the updater file in files_to_update +# We don't want the updater file in files_to_update if( updater_filename in files_to_update ): files_to_update.remove( updater_filename ); local_versions = {}; remote_versions = {}; +subdirs = []; read_local_versions_file( local_versions, versions_filename ); if( not local_versions.has_key( updater_filename )): local_versions[ updater_filename ] = 0; @@ -141,9 +151,7 @@ updater_backup_url_lines = []; try: print "Downloading the base file list..."; - base_url_file = urllib2.urlopen(base_url); - base_url_lines = base_url_file.readlines() - base_url_file.close(); + base_url_lines = get_remote_versions_data( base_url ); except: print "Base file list download failed."; try: @@ -155,12 +163,11 @@ print "Couldn't fetch the base URL information or the updater backup URL for some reason. You may have to update the updater via other means or try again later."; sys.exit( 1 ); if( 0 != len( base_url_lines )): # If we could download the View CVS directory listing... - process_raw_remote_versions_data( remote_versions, base_url_lines ); + print "Processing the base file list..."; + process_raw_remote_versions_data( remote_versions, base_url_lines, "" ); else: print "Using the updater downloaded from the updater backup URL..."; if( 0 != len( updater_backup_url_lines )): # If we could download the updater from the backup URL - for updater_backup_url_line in updater_backup_url_lines: - print "DEBUG: updater_backup_url_line: [%s]" % ( updater_backup_url_line.rstrip() ); write_file( updater_filename, updater_backup_url_lines ); print "Executing the backup updater URL updated updater.py..."; execfile( updater_filename ); @@ -168,16 +175,28 @@ else: print "Couldn't fetch the base URL information and the updater backup URL returned no data. You may have to update the updater via other means or try again later."; sys.exit( 1 ); -#print "DEBUG: local_versions: [%s]" % ( local_versions ); -#print "DEBUG: remote_versions: [%s]" % ( remote_versions ); +for file_to_update in files_to_update: + if( -1 != file_to_update.find( "/" )): + file_to_update_dir = os.path.dirname( file_to_update ); + if( not file_to_update_dir in subdirs ): + subdirs.append( file_to_update_dir + "/" ); +for subdir in subdirs: + subdir_url = base_url + subdir; + subdir_url_lines = []; + try: + print "Downloading the %s file list..." % ( subdir ); + subdir_url_lines = get_remote_versions_data( subdir_url ); + except: + print "%s file list download failed." % ( subdir ); + if( 0 != len( subdir_url_lines )): # If we could download the View CVS directory listing... + print "Processing the %s file list..." % ( subdir ); + process_raw_remote_versions_data( remote_versions, subdir_url_lines, subdir ); if( needs_update( updater_filename, local_versions, remote_versions )): try: downloaded_file_lines = download_file( download_base_url, updater_filename, remote_versions[ updater_filename ] ); except: print "Couldn't fetch the updater directly. You may have to update the updater via other means or try again later."; sys.exit( 1 ); - #for downloaded_file_line in downloaded_file_lines: - # print "DEBUG: downloaded_file_line: [%s]" % ( downloaded_file_line.rstrip() ); write_file( updater_filename, downloaded_file_lines ); local_versions[ updater_filename ] = remote_versions[ updater_filename ]; print "Writing updated local versions data file..."; @@ -185,8 +204,18 @@ print "Executing the updated updater.py..."; execfile( updater_filename ); sys.exit( 0 ); # execfile() doesn't appear to return, but just in case... +updated_a_file_flag = False; for file_to_update in files_to_update: if( needs_update( file_to_update, local_versions, remote_versions )): - print "DEBUG: %s needs update" % ( file_to_update ); -print "Not implemented yet" -sys.exit( 1 ); + try: + downloaded_file_lines = download_file( download_base_url, file_to_update, remote_versions[ file_to_update ] ); + except: + print "Couldn't fetch the updater directly. You may have to update the updater via other means or try again later."; + sys.exit( 1 ); + downloaded_file_lines = do_revision_substitution( downloaded_file_lines, remote_versions[ file_to_update ] ); + write_file( file_to_update, downloaded_file_lines ); + updated_a_file_flag = True; + local_versions[ file_to_update ] = remote_versions[ file_to_update ]; +if( updated_a_file_flag ): + print "Writing updated local versions data file..."; + write_local_versions_file( local_versions, versions_filename ); From zothar at freenetproject.org Tue Nov 28 02:04:32 2006 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Tue, 28 Nov 2006 02:04:32 +0000 (UTC) Subject: [Pyfreenet] r11081 - trunk/apps/pyFreenet Message-ID: <20061128020432.5736F9BD09@emu.freenetproject.org> Author: zothar Date: 2006-11-28 02:04:26 +0000 (Tue, 28 Nov 2006) New Revision: 11081 Modified: trunk/apps/pyFreenet/updater.py Log: pyfcp updater: Don't do anything with any other files until after we've determined we don't need to update the updater. Modified: trunk/apps/pyFreenet/updater.py =================================================================== --- trunk/apps/pyFreenet/updater.py 2006-11-28 02:00:30 UTC (rev 11080) +++ trunk/apps/pyFreenet/updater.py 2006-11-28 02:04:26 UTC (rev 11081) @@ -175,6 +175,19 @@ else: print "Couldn't fetch the base URL information and the updater backup URL returned no data. You may have to update the updater via other means or try again later."; sys.exit( 1 ); +if( needs_update( updater_filename, local_versions, remote_versions )): + try: + downloaded_file_lines = download_file( download_base_url, updater_filename, remote_versions[ updater_filename ] ); + except: + print "Couldn't fetch the updater directly. You may have to update the updater via other means or try again later."; + sys.exit( 1 ); + write_file( updater_filename, downloaded_file_lines ); + local_versions[ updater_filename ] = remote_versions[ updater_filename ]; + print "Writing updated local versions data file..."; + write_local_versions_file( local_versions, versions_filename ); + print "Executing the updated updater.py..."; + execfile( updater_filename ); + sys.exit( 0 ); # execfile() doesn't appear to return, but just in case... for file_to_update in files_to_update: if( -1 != file_to_update.find( "/" )): file_to_update_dir = os.path.dirname( file_to_update ); @@ -191,19 +204,6 @@ if( 0 != len( subdir_url_lines )): # If we could download the View CVS directory listing... print "Processing the %s file list..." % ( subdir ); process_raw_remote_versions_data( remote_versions, subdir_url_lines, subdir ); -if( needs_update( updater_filename, local_versions, remote_versions )): - try: - downloaded_file_lines = download_file( download_base_url, updater_filename, remote_versions[ updater_filename ] ); - except: - print "Couldn't fetch the updater directly. You may have to update the updater via other means or try again later."; - sys.exit( 1 ); - write_file( updater_filename, downloaded_file_lines ); - local_versions[ updater_filename ] = remote_versions[ updater_filename ]; - print "Writing updated local versions data file..."; - write_local_versions_file( local_versions, versions_filename ); - print "Executing the updated updater.py..."; - execfile( updater_filename ); - sys.exit( 0 ); # execfile() doesn't appear to return, but just in case... updated_a_file_flag = False; for file_to_update in files_to_update: if( needs_update( file_to_update, local_versions, remote_versions )): From zothar at freenetproject.org Tue Nov 28 03:05:40 2006 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Tue, 28 Nov 2006 03:05:40 +0000 (UTC) Subject: [Pyfreenet] r11084 - trunk/apps/pyFreenet Message-ID: <20061128030540.E2DE59CAEF@emu.freenetproject.org> Author: zothar Date: 2006-11-28 03:05:38 +0000 (Tue, 28 Nov 2006) New Revision: 11084 Modified: trunk/apps/pyFreenet/minibot.py trunk/apps/pyFreenet/refbot.py Log: refbot: Track whether a command was sent via a private message. Now honor a 'die' command only via private message. Update the details of how to run your own refbot. Modified: trunk/apps/pyFreenet/minibot.py =================================================================== --- trunk/apps/pyFreenet/minibot.py 2006-11-28 02:43:22 UTC (rev 11083) +++ trunk/apps/pyFreenet/minibot.py 2006-11-28 03:05:38 UTC (rev 11084) @@ -43,6 +43,11 @@ peer is telling us to do something only owners can tell us to """ +class NotPrivateMessage(Exception): + """ + peer is telling us to do something that we'll only do when it's sent in a private message + """ + class TimeToQuit(Exception): """ Terminates the bot @@ -626,16 +631,16 @@ #@+node:on_pubmsg def on_pubmsg(self, msg): - self.on_msg(self.pubmsg, msg) + self.on_msg(self.pubmsg, msg, False) #@-node:on_pubmsg #@+node:on_privmsg def on_privmsg(self, msg): - self.on_msg(self.privmsg, msg) + self.on_msg(self.privmsg, msg, True) #@-node:on_privmsg - #@+node:on_msg - def on_msg(self, replyfunc, msg): + #@+node:on_msgf + def on_msg(self, replyfunc, msg, is_from_privmsg): check_time_range = 10 ignore_time = 15 @@ -679,17 +684,19 @@ if meth: try: - meth(replyfunc, args) + meth(replyfunc, is_from_privmsg, args) except NotOwner: pass + except NotPrivateMessage: + pass else: - if not self.on_unknownCommand(replyfunc, cmd, msg): + if not self.on_unknownCommand(replyfunc, is_from_privmsg, cmd, msg): self.privmsg( "error Unrecognised command '%s' - type 'help' for help" % cmd) #@-node:on_msg #@+node:on_unknownCommand - def on_unknownCommand(self, replyfunc, cmd, msg): + def on_unknownCommand(self, replyfunc, is_from_privmsg, cmd, msg): """ Handler for messages that don't match an existing command handler method @@ -748,7 +755,7 @@ #@+others #@+node:cmd_hi - def cmd_hi(self, replyfunc, args): + def cmd_hi(self, replyfunc, is_from_privmsg, args): log("cmd_hi: %s" % str(args)) @@ -756,13 +763,13 @@ #@-node:cmd_hi #@+node:cmd_error - def cmd_error(self, replyfunc, args): + def cmd_error(self, replyfunc, is_from_privmsg, args): pass #@-node:cmd_error #@+node:cmd_help - def cmd_help(self, replyfunc, args): + def cmd_help(self, replyfunc, is_from_privmsg, args): self.privmsg( "I am a bot", @@ -773,11 +780,14 @@ #@-node:cmd_help #@+node:cmd_die - def cmd_die(self, replyfunc, args): + def cmd_die(self, replyfunc, is_from_privmsg, args): #log("** die: %s %s" % (self.peernick, args)) self.barfIfNotOwner() + if(not is_from_privmsg): + self.privmsg("Sorry, but that command will only be honored in a /msg") + raise NotPrivateMessage() self.privmsg("Goodbye, master") self.bot.die() Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2006-11-28 02:43:22 UTC (rev 11083) +++ trunk/apps/pyFreenet/refbot.py 2006-11-28 03:05:38 UTC (rev 11084) @@ -358,7 +358,7 @@ """ self.action( self.channel, - "is a Freenet NodeRef Swap-bot (www.freenet.org.nz/pyfcp/ + latest SVN refbot.py minibot.py and fcp/node.py)" + "is a Freenet NodeRef Swap-bot (install http://www.freenet.org.nz/pyfcp/ + run http://freenet.xzwq.net/pyfcp/updater.py then run refbot.py)" ) if(self.spam_interval > 0): self.after(self.spam_interval, self.spamChannel) @@ -518,7 +518,7 @@ #@+others #@+node:on_unknownCommand - def on_unknownCommand(self, replyfunc, cmd, msg): + def on_unknownCommand(self, replyfunc, is_from_privmsg, cmd, msg): """ Pick up possible URLs """ @@ -548,7 +548,7 @@ #@+others #@+node:cmd_hi - def cmd_hi(self, replyfunc, args): + def cmd_hi(self, replyfunc, is_from_privmsg, args): log("cmd_hi: %s" % str(args)) @@ -558,12 +558,12 @@ #@-node:cmd_hi #@+node:cmd_error - def cmd_error(self, replyfunc, args): + def cmd_error(self, replyfunc, is_from_privmsg, args): pass #@-node:cmd_error #@+node:cmd_help - def cmd_help(self, replyfunc, args): + def cmd_help(self, replyfunc, is_from_privmsg, args): self.privmsg( "I am a bot for exchanging freenet noderefs", @@ -572,14 +572,14 @@ "Available commands:", " addref - add ref at to my node", " getref - print out my own ref so you can add me", - " die - terminate me (owner only)", + " die - terminate me (PM from owner only)", " help - display this help", "** (end of help listing) **" ) #@-node:cmd_help #@+node:cmd_addref - def cmd_addref(self, replyfunc, args): + def cmd_addref(self, replyfunc, is_from_privmsg, args): if len(args) != 1: self.privmsg( @@ -599,7 +599,7 @@ #@-node:cmd_addref #@+node:cmd_getref - def cmd_getref(self, replyfunc, args): + def cmd_getref(self, replyfunc, is_from_privmsg, args): replyfunc("My ref is at %s" % self.bot.refurl) From zothar at freenetproject.org Tue Nov 28 03:08:44 2006 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Tue, 28 Nov 2006 03:08:44 +0000 (UTC) Subject: [Pyfreenet] r11085 - trunk/apps/pyFreenet Message-ID: <20061128030844.C5F849CA10@emu.freenetproject.org> Author: zothar Date: 2006-11-28 03:08:34 +0000 (Tue, 28 Nov 2006) New Revision: 11085 Modified: trunk/apps/pyFreenet/updater.py Log: pyfcp updater: Note the revision of a downloading updated file. Modified: trunk/apps/pyFreenet/updater.py =================================================================== --- trunk/apps/pyFreenet/updater.py 2006-11-28 03:05:38 UTC (rev 11084) +++ trunk/apps/pyFreenet/updater.py 2006-11-28 03:08:34 UTC (rev 11085) @@ -42,7 +42,7 @@ return substituted_file_lines; def download_file( download_base_url, filename, version ): - print "Downloading %s ..." % ( filename ); + print "Downloading %s r%d ..." % ( filename, version ); download_url = "%s?rev=%d" % ( os.path.join( download_base_url, filename ), version ); download_url_file = urllib2.urlopen(download_url); download_url_lines = download_url_file.readlines() From zothar at freenetproject.org Thu Nov 30 13:05:09 2006 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Thu, 30 Nov 2006 13:05:09 +0000 (UTC) Subject: [Pyfreenet] r11136 - in trunk/apps/pyFreenet: . fcp Message-ID: <20061130130509.72E939BE02@emu.freenetproject.org> Author: zothar Date: 2006-11-30 13:05:02 +0000 (Thu, 30 Nov 2006) New Revision: 11136 Modified: trunk/apps/pyFreenet/fcp/node.py trunk/apps/pyFreenet/refbot.py Log: refbot: Added a version command. Re-ordered a few methods. Expanded the help text with more information about running a refbot. Modified: trunk/apps/pyFreenet/fcp/node.py =================================================================== --- trunk/apps/pyFreenet/fcp/node.py 2006-11-30 10:36:54 UTC (rev 11135) +++ trunk/apps/pyFreenet/fcp/node.py 2006-11-30 13:05:02 UTC (rev 11136) @@ -180,6 +180,10 @@ calling modes. """ + + svnLongRevision = "$Revision$" + svnRevision = svnLongRevision[ 11 : -2 ] + #@ @+others #@+node:attribs noCloseSocket = True Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2006-11-30 10:36:54 UTC (rev 11135) +++ trunk/apps/pyFreenet/refbot.py 2006-11-30 13:05:02 UTC (rev 11136) @@ -547,37 +547,11 @@ # command handlers #@+others - #@+node:cmd_hi - def cmd_hi(self, replyfunc, is_from_privmsg, args): - - log("cmd_hi: %s" % str(args)) - - self.action("waits for a bit") - - self.privmsg("Hi - type 'help' for help") - - #@-node:cmd_hi #@+node:cmd_error def cmd_error(self, replyfunc, is_from_privmsg, args): pass #@-node:cmd_error - #@+node:cmd_help - def cmd_help(self, replyfunc, is_from_privmsg, args): - - self.privmsg( - "I am a bot for exchanging freenet noderefs", - "I can be downloaded from http://www.freenet.org.nz/pyfcp/ as part of pyfcp (or from Freenet's SVN)", - "My version numbers are refbot.py at r%s and minibot.py at r%s" % (FreenetNodeRefBot.svnRevision, MiniBot.svnRevision), - "Available commands:", - " addref - add ref at to my node", - " getref - print out my own ref so you can add me", - " die - terminate me (PM from owner only)", - " help - display this help", - "** (end of help listing) **" - ) - - #@-node:cmd_help #@+node:cmd_addref def cmd_addref(self, replyfunc, is_from_privmsg, args): @@ -604,6 +578,44 @@ replyfunc("My ref is at %s" % self.bot.refurl) #@-node:cmd_getref + #@+node:cmd_help + def cmd_help(self, replyfunc, is_from_privmsg, args): + + self.privmsg( + "I am a bot for exchanging freenet noderefs", + "I can be downloaded from http://www.freenet.org.nz/pyfcp/ as part of pyfcp (or from Freenet's SVN), ", + "though I am currently using a few files that are newer than the latest official release. ", + "You can get those too by downloading https://emu.freenetproject.org/svn/trunk/apps/pyFreenet/updater.py", + "to the directory pyfcp was installed to and running it.", + "My version numbers are refbot.py at r%s and minibot.py at r%s" % (FreenetNodeRefBot.svnRevision, MiniBot.svnRevision), + "Available commands:", + " addref - add ref at to my node", + " die - terminate me (PM from owner only)", + " getref - print out my own ref so you can add me", + " help - display this help", + " version - display the above version information", + "** (end of help listing) **" + ) + + #@-node:cmd_help + #@+node:cmd_hi + def cmd_hi(self, replyfunc, is_from_privmsg, args): + + log("cmd_hi: %s" % str(args)) + + self.action("waits for a bit") + + self.privmsg("Hi - type 'help' for help") + + #@-node:cmd_hi + #@+node:cmd_version + def cmd_version(self, replyfunc, is_from_privmsg, args): + + self.privmsg( + "refbot.py: r%s minibot.py: r%s fcp/node.py: r%s" % (FreenetNodeRefBot.svnRevision, MiniBot.svnRevision, fcp.FCPNode.svnRevision), + ) + + #@-node:cmd_version #@-others #@-node:command handlers From zothar at freenetproject.org Thu Nov 30 13:13:36 2006 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Thu, 30 Nov 2006 13:13:36 +0000 (UTC) Subject: [Pyfreenet] r11137 - in trunk/apps/pyFreenet: . fcp Message-ID: <20061130131336.6C97820B0CD@emu.freenetproject.org> Author: zothar Date: 2006-11-30 13:13:31 +0000 (Thu, 30 Nov 2006) New Revision: 11137 Modified: trunk/apps/pyFreenet/fcp/node.py trunk/apps/pyFreenet/refbot.py Log: refbot: Add message about registering the owner's IRC nick to the setup process. Set the svn:keywords on fcp/node.py for Revision substitution. Property changes on: trunk/apps/pyFreenet/fcp/node.py ___________________________________________________________________ Name: svn:keywords + Revision Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2006-11-30 13:05:02 UTC (rev 11136) +++ trunk/apps/pyFreenet/refbot.py 2006-11-30 13:13:31 UTC (rev 11137) @@ -216,6 +216,9 @@ opts = {} + print "** You will need to be sure to register your IRC nick with freenode" + print "** so that someone else can't /msg your bot and shut it down" + print "** while you're away. Use /msg nickserv register " opts['ownerircnick'] = prompt("Enter your usual freenode.net nick") opts['usernick'] = prompt("Enter your node's name", opts['ownerircnick']) print "** You need to choose a new password, since this bot will" From zothar at freenetproject.org Thu Nov 30 15:15:31 2006 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Thu, 30 Nov 2006 15:15:31 +0000 (UTC) Subject: [Pyfreenet] r11139 - trunk/apps/pyFreenet Message-ID: <20061130151531.107C19CA73@emu.freenetproject.org> Author: zothar Date: 2006-11-30 15:15:28 +0000 (Thu, 30 Nov 2006) New Revision: 11139 Modified: trunk/apps/pyFreenet/refbot.py trunk/apps/pyFreenet/updater.py Log: refbot/updater: Fix the updater when run with 'python updater.py' instead of './updater.py'. Fix refbot so that it won't accept a node name that will result in a bot IRC nick that's too long. Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2006-11-30 13:52:50 UTC (rev 11138) +++ trunk/apps/pyFreenet/refbot.py 2006-11-30 15:15:28 UTC (rev 11139) @@ -220,7 +220,12 @@ print "** so that someone else can't /msg your bot and shut it down" print "** while you're away. Use /msg nickserv register " opts['ownerircnick'] = prompt("Enter your usual freenode.net nick") - opts['usernick'] = prompt("Enter your node's name", opts['ownerircnick']) + while( 1 ): + opts['usernick'] = prompt("Enter your node's name", opts['ownerircnick']) + if( len( opts['usernick'] ) > 12 ): + print "The node's name used by the bot cannot be any longer than 12 characters because the bot's IRC nickname cannot be any longer than 16 characters" + else: + break print "** You need to choose a new password, since this bot will" print "** register this password with freenode 'nickserv', and" print "** on subsequent runs, will identify with this password" Modified: trunk/apps/pyFreenet/updater.py =================================================================== --- trunk/apps/pyFreenet/updater.py 2006-11-30 13:52:50 UTC (rev 11138) +++ trunk/apps/pyFreenet/updater.py 2006-11-30 15:15:28 UTC (rev 11139) @@ -135,7 +135,7 @@ versions_file.close(); # We want to work in the directory where pyfcp is installed -os.chdir( os.path.dirname( sys.argv[ 0 ] )); +os.chdir( os.path.dirname( os.path.abspath( sys.argv[ 0 ] ))); # We don't want the updater file in files_to_update if( updater_filename in files_to_update ): From zothar at freenetproject.org Thu Nov 30 15:40:52 2006 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Thu, 30 Nov 2006 15:40:52 +0000 (UTC) Subject: [Pyfreenet] r11140 - trunk/apps/pyFreenet Message-ID: <20061130154052.BD4849CAF4@emu.freenetproject.org> Author: zothar Date: 2006-11-30 15:40:49 +0000 (Thu, 30 Nov 2006) New Revision: 11140 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: Explain that the bot's IRC nick will have _bot added to the end of the given usernick value. Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2006-11-30 15:15:28 UTC (rev 11139) +++ trunk/apps/pyFreenet/refbot.py 2006-11-30 15:40:49 UTC (rev 11140) @@ -223,7 +223,7 @@ while( 1 ): opts['usernick'] = prompt("Enter your node's name", opts['ownerircnick']) if( len( opts['usernick'] ) > 12 ): - print "The node's name used by the bot cannot be any longer than 12 characters because the bot's IRC nickname cannot be any longer than 16 characters" + print "The node's name used by the bot cannot be any longer than 12 characters because the bot's IRC nickname cannot be any longer than 16 characters and the bot IRC nickname will be this value with '_bot' added to the end." else: break print "** You need to choose a new password, since this bot will" From zothar at freenetproject.org Thu Nov 30 16:50:40 2006 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Thu, 30 Nov 2006 16:50:40 +0000 (UTC) Subject: [Pyfreenet] r11141 - trunk/apps/pyFreenet Message-ID: <20061130165040.18B6F9CAEB@emu.freenetproject.org> Author: zothar Date: 2006-11-30 16:50:36 +0000 (Thu, 30 Nov 2006) New Revision: 11141 Modified: trunk/apps/pyFreenet/minibot.py Log: refbot: Fix the bot not continuing after successfully registering with nickserv. Modified: trunk/apps/pyFreenet/minibot.py =================================================================== --- trunk/apps/pyFreenet/minibot.py 2006-11-30 15:40:49 UTC (rev 11140) +++ trunk/apps/pyFreenet/minibot.py 2006-11-30 16:50:36 UTC (rev 11141) @@ -247,6 +247,7 @@ #@+node:on_notice def on_notice(self, sender, msg): + log("** notice: %s: %s" % (sender, msg)) if "Please wait 30 seconds before using REGISTER again" in msg: log("Just registered password, waiting 30 seconds...") self.after(31, self.registerPassword) @@ -263,8 +264,10 @@ self.on_ready() self.after(1, self._pinger) - elif 1: - log("** notice: %s: %s" % (sender, msg)) + elif "Your nickname is now registered" in msg: + log("New bot IRC Nick registered") + self.on_ready() + self.after(1, self._pinger) #@-node:on_notice #@+node:on_ready From zothar at freenetproject.org Thu Nov 30 17:00:17 2006 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Thu, 30 Nov 2006 17:00:17 +0000 (UTC) Subject: [Pyfreenet] r11142 - trunk/apps/pyFreenet Message-ID: <20061130170017.A13369CAEB@emu.freenetproject.org> Author: zothar Date: 2006-11-30 17:00:15 +0000 (Thu, 30 Nov 2006) New Revision: 11142 Modified: trunk/apps/pyFreenet/minibot.py trunk/apps/pyFreenet/refbot.py Log: refbot: Remove some unused variables Modified: trunk/apps/pyFreenet/minibot.py =================================================================== --- trunk/apps/pyFreenet/minibot.py 2006-11-30 16:50:36 UTC (rev 11141) +++ trunk/apps/pyFreenet/minibot.py 2006-11-30 17:00:15 UTC (rev 11142) @@ -19,23 +19,6 @@ args = sys.argv[1:] nargs = len(args) -# The server we want to connect to -#HOST = 'mesa.az.us.undernet.org' -defaultHost = 'irc.freenode.net' - -# The connection port which is usually 6667 -defaultPort = 6667 - -# The bot's nickname -#defaultNick = 'aum_bot' - -# The default channel for the bot -#chan = '#freenet-bottest' -chan = '#freenet-refs' - -# Here we store all the messages from server -readbuffer = '' - #@-node:globals #@+node:exceptions class NotOwner(Exception): Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2006-11-30 16:50:36 UTC (rev 11141) +++ trunk/apps/pyFreenet/refbot.py 2006-11-30 17:00:15 UTC (rev 11142) @@ -31,31 +31,11 @@ args = sys.argv[1:] nargs = len(args) -# The server we want to connect to -#HOST = 'mesa.az.us.undernet.org' -defaultHost = 'irc.freenode.net' - -# The connection port which is usually 6667 -defaultPort = 6667 - -# The bot's nickname -#defaultNick = 'aum_bot' - ident = 'FreenetRefBot' -# The default channel for the bot -#chan = '#freenet-bottest' -chan = '#freenet-refs' - -# Here we store all the messages from server -readbuffer = '' - obscenities = ["fuck", "cunt", "shit", "asshole", "fscking", "wank"] reactToObscenities = False -svnLongRevision = "$Revision$" -svnRevision = svnLongRevision[ 11 : -2 ] - #@-node:globals #@+node:exceptions class NotOwner(Exception): From zothar at freenetproject.org Thu Nov 30 17:53:52 2006 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Thu, 30 Nov 2006 17:53:52 +0000 (UTC) Subject: [Pyfreenet] r11143 - trunk/apps/pyFreenet Message-ID: <20061130175352.2F5399CA9F@emu.freenetproject.org> Author: zothar Date: 2006-11-30 17:53:50 +0000 (Thu, 30 Nov 2006) New Revision: 11143 Modified: trunk/apps/pyFreenet/minibot.py trunk/apps/pyFreenet/refbot.py Log: refbot: Tweak nickserv identify process. Modified: trunk/apps/pyFreenet/minibot.py =================================================================== --- trunk/apps/pyFreenet/minibot.py 2006-11-30 17:00:15 UTC (rev 11142) +++ trunk/apps/pyFreenet/minibot.py 2006-11-30 17:53:50 UTC (rev 11143) @@ -90,7 +90,8 @@ realname = "%s the MiniBot" % self.nick self.realname = realname - self.running = 1 + self.hasIdentified = False + self._running = False self.peers = {} self.lastSendTime = time.time() self.sendlock = threading.Lock() @@ -131,6 +132,7 @@ except NotReceiving: self.sock.close() + self.hasIdentified = False log("** ERROR: server is ignoring us, restarting in 3 seconds...") time.sleep(3) self._restarted = True @@ -194,7 +196,7 @@ self.after(1, self._sender) self.after(5, self._watchdog) #self.after(1, self._pinger) - self.after(5, self.identifyPassword) # freenode seemd to need an extra bump for a new identity (and even then there's a one restart problem, but at least it works) + self.after(5, self.identifyPassword) #@-node:connect #@+node:handlers @@ -206,6 +208,8 @@ """ Handles messages from server """ + if typ not in [ '353', '409' ]: + log("** server: %s %s" % (repr(typ), msg)) if "End of /MOTD" in msg: log("** joining channel %s" % self.channel) self.sendline('JOIN ' + self.channel) #Join a channel @@ -221,10 +225,6 @@ self.usersInChan.extend(msgparts[2:]) log("** users in %s: %s" % (self.channel, self.usersInChan)) return - - elif 1: - if typ != '409': - log("** server: %s %s" % (repr(typ), msg)) #@-node:on_server_msg #@+node:on_notice @@ -244,11 +244,12 @@ elif "Password accepted - you are now recognized" in msg: log("Password accepted") + self.hasIdentified = True self.on_ready() self.after(1, self._pinger) elif "Your nickname is now registered" in msg: - log("New bot IRC Nick registered") + log("Password registered") self.on_ready() self.after(1, self._pinger) @@ -481,7 +482,6 @@ sends a 'register ' command to nickserv """ self.privmsg("nickserv", "register %s" % self.password) - pass #@-node:registerPassword #@+node:identifyPassword @@ -489,8 +489,9 @@ """ sends an 'identify ' command to nickserv """ + if(self.hasIdentified): + return; # Don't need to identify if we have already self.privmsg("nickserv", "identify %s" % self.password) - pass #@-node:identifyPassword #@+node:after Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2006-11-30 17:00:15 UTC (rev 11142) +++ trunk/apps/pyFreenet/refbot.py 2006-11-30 17:53:50 UTC (rev 11143) @@ -98,6 +98,8 @@ # get local attribs self.nodenick = opts['usernick'] + self.refs = opts['refs'] + self.refurl = opts['refurl'] if(opts.has_key('ircchannel')): self.chan = opts['ircchannel'] else: @@ -128,7 +130,6 @@ else: self.number_of_refs_to_collect = 10 needToSave = True - self.refs = opts['refs'] if(opts.has_key('telnethost')): self.tmci_host = opts['telnethost'] needToSave = True @@ -147,7 +148,6 @@ else: self.tmci_port = 2323; needToSave = True - self.refurl = opts['refurl'] # for internal use shadow of MiniBot configs self.irc_host = kw[ 'host' ] @@ -287,6 +287,21 @@ #@-node:load #@+node:events # handle events + #@+node:on_chanmsg + def on_chanmsg(self, sender, target, msg): + """ + Handles a message on the channel, not addressed to the bot + """ + log("** chanmsg: %s => %s: %s" % (sender, target, repr(msg))) + + if reactToObscenities: + m = msg.lower() + for o in obscenities: + if o in m: + self.action(self.channel, "blushes") + break + + #@-node:on_chanmsg #@+node:on_ready def on_ready(self): """ @@ -303,21 +318,6 @@ log("****** on_ready") #@-node:on_ready - #@+node:on_chanmsg - def on_chanmsg(self, sender, target, msg): - """ - Handles a message on the channel, not addressed to the bot - """ - log("** chanmsg: %s => %s: %s" % (sender, target, repr(msg))) - - if reactToObscenities: - m = msg.lower() - for o in obscenities: - if o in m: - self.action(self.channel, "blushes") - break - - #@-node:on_chanmsg #@-node:events #@+node:actions # action methods From zothar at freenetproject.org Thu Nov 30 20:34:42 2006 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Thu, 30 Nov 2006 20:34:42 +0000 (UTC) Subject: [Pyfreenet] r11146 - trunk/apps/pyFreenet Message-ID: <20061130203442.75C2A9CAEE@emu.freenetproject.org> Author: zothar Date: 2006-11-30 20:34:40 +0000 (Thu, 30 Nov 2006) New Revision: 11146 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: Now check that the node actually added the ref. Lengthen the default 'trade with me' and 'how to get me' message intervals. Tweak a error message. Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2006-11-30 20:01:25 UTC (rev 11145) +++ trunk/apps/pyFreenet/refbot.py 2006-11-30 20:34:40 UTC (rev 11146) @@ -118,12 +118,12 @@ if(opts.has_key('greetinterval')): self.greet_interval = opts['greetinterval'] else: - self.greet_interval = 1200 + self.greet_interval = 1800 needToSave = True if(opts.has_key('spaminterval')): self.spam_interval = opts['spaminterval'] else: - self.spam_interval = 3600 + self.spam_interval = 7200 needToSave = True if(opts.has_key('refsperrun')): self.number_of_refs_to_collect = opts['refsperrun'] @@ -410,7 +410,7 @@ elif(-1 == adderThread.status): error_str = "the URL does not contain a valid ref. Please correct the ref at the URL or the URL itself <%s> and try again." % (adderThread.url) elif(-2 == adderThread.status): - error_str = "there was a problem fetching the given URL. Please correct the URL <%s> and try again, or try again later if you suspect server troubles." % (adderThread.url) + error_str = "there was a problem fetching the given URL. Please correct the URL <%s> and try again, or try again later/try a different server if you suspect server troubles." % (adderThread.url) elif(-3 == adderThread.status): error_str = "there was a problem talking to the node. Please try again later." elif(-4 == adderThread.status): @@ -419,6 +419,8 @@ error_str = "the node reports that it already has a ref with its own identity. Ref not added." elif(-6 == adderThread.status): error_str = adderThread.error_msg + elif(-7 == adderThread.status): + error_str = "the node could nott 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." refs_to_go = self.number_of_refs_to_collect - self.nrefs refs_to_go_str = '' if refs_to_go > 0: @@ -662,7 +664,7 @@ return try: - f = fcp.FCPNode( host = self.fcp_host, port = self.fcp_port ) + f = fcp.FCPNode( host = self.fcp_host, port = self.fcp_port, verbosity = fcp.DETAIL ) if( have_plugin_module ): try: self.plugin_args[ "fcpNode" ] = f; @@ -726,6 +728,19 @@ f.shutdown(); return + #try: + if( 1 ): + returned_peer = f.modifypeer( NodeIdentifier = ref_fieldset[ "identity" ] ) + if( type( returned_peer ) == type( [] )): + returned_peer = returned_peer[ 0 ]; + if( returned_peer[ "header" ] == "UnknownNodeIdentifier" ): + self.status = -7 + self.error_msg = "Node couldn't add peer for some reason." + f.shutdown(); + return + #except Exception, msg: + # # We'll let this part fail open for now + # pass if( have_plugin_module ): try: plugin_result = botplugin.post_add( self.plugin_args ); From zothar at freenetproject.org Thu Nov 30 20:53:11 2006 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Thu, 30 Nov 2006 20:53:11 +0000 (UTC) Subject: [Pyfreenet] r11148 - trunk/apps/pyFreenet Message-ID: <20061130205311.9884E9CAD7@emu.freenetproject.org> Author: zothar Date: 2006-11-30 20:53:09 +0000 (Thu, 30 Nov 2006) New Revision: 11148 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: Mention to the user the need to refresh their ref URL once they get a physical.udp line in their ref. Uncomment an exception handler that had gotten commented during debugging. Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2006-11-30 20:42:12 UTC (rev 11147) +++ trunk/apps/pyFreenet/refbot.py 2006-11-30 20:53:09 UTC (rev 11148) @@ -387,7 +387,7 @@ adderThread.join() log("adderThread has status: %s url: %s error_msg: %s" % (adderThread.status, adderThread.url, adderThread.error_msg)) self.adderThreads.remove(adderThread) - if(1 == adderThread.status): + if(0 < adderThread.status): self.refs.append(adderThread.url) self.save() self.nrefs += 1 @@ -399,6 +399,8 @@ if( refs_to_go > 1 ): refs_plural_str = "s" 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 self.nrefs >= self.number_of_refs_to_collect: log("Got our %d refs, now terminating!" % ( self.number_of_refs_to_collect )) @@ -728,8 +730,7 @@ f.shutdown(); return - #try: - if( 1 ): + try: returned_peer = f.modifypeer( NodeIdentifier = ref_fieldset[ "identity" ] ) if( type( returned_peer ) == type( [] )): returned_peer = returned_peer[ 0 ]; @@ -738,9 +739,9 @@ self.error_msg = "Node couldn't add peer for some reason." f.shutdown(); return - #except Exception, msg: - # # We'll let this part fail open for now - # pass + except Exception, msg: + # We'll let this part fail open for now + pass if( have_plugin_module ): try: plugin_result = botplugin.post_add( self.plugin_args ); From zothar at freenetproject.org Thu Nov 30 21:30:19 2006 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Thu, 30 Nov 2006 21:30:19 +0000 (UTC) Subject: [Pyfreenet] r11150 - trunk/apps/pyFreenet Message-ID: <20061130213019.B6DE720B239@emu.freenetproject.org> Author: zothar Date: 2006-11-30 21:30:17 +0000 (Thu, 30 Nov 2006) New Revision: 11150 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: The bot now checks for the existence of the same fields the Freenet node does before trying to add a ref and will now complain with the name of the field it first checked but didn't find. Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2006-11-30 21:13:01 UTC (rev 11149) +++ trunk/apps/pyFreenet/refbot.py 2006-11-30 21:30:17 UTC (rev 11150) @@ -410,7 +410,7 @@ if(0 == adderThread.status): error_str = "there was a general error while trying to add your ref. Try again and/or try again later." elif(-1 == adderThread.status): - error_str = "the URL does not contain a valid ref. Please correct the ref at the URL or the URL itself <%s> and try again." % (adderThread.url) + error_str = "the URL does not contain a valid ref (%s). Please correct the ref at the URL or the URL itself <%s> and try again." % (adderThread.error_msg, adderThread.url) elif(-2 == adderThread.status): error_str = "there was a problem fetching the given URL. Please correct the URL <%s> and try again, or try again later/try a different server if you suspect server troubles." % (adderThread.url) elif(-3 == adderThread.status): @@ -656,14 +656,12 @@ continue; if(not ref_fieldset.has_key(reflinefields[ 0 ])): ref_fieldset[ reflinefields[ 0 ]] = reflinefields[ 1 ] - if(not ref_fieldset.has_key("identity")): - self.status = -1 # invalid ref found at URL - self.error_msg = "No identity field in ref" - return - if(not ref_fieldset.has_key("myName")): - self.status = -1 # invalid ref found at URL - self.error_msg = "No myName field in ref" - return + 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)): + self.status = -1 # invalid ref found at URL + self.error_msg = "No %s field in ref" % ( require_ref_field ); + return try: f = fcp.FCPNode( host = self.fcp_host, port = self.fcp_port, verbosity = fcp.DETAIL ) From zothar at freenetproject.org Thu Nov 30 21:52:23 2006 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Thu, 30 Nov 2006 21:52:23 +0000 (UTC) Subject: [Pyfreenet] r11152 - trunk/apps/pyFreenet Message-ID: <20061130215223.5384920B23A@emu.freenetproject.org> Author: zothar Date: 2006-11-30 21:52:21 +0000 (Thu, 30 Nov 2006) New Revision: 11152 Modified: trunk/apps/pyFreenet/minibot.py Log: refbot: Make the bot more accepting of different ways of addressing it. Modified: trunk/apps/pyFreenet/minibot.py =================================================================== --- trunk/apps/pyFreenet/minibot.py 2006-11-30 21:35:09 UTC (rev 11151) +++ trunk/apps/pyFreenet/minibot.py 2006-11-30 21:52:21 UTC (rev 11152) @@ -391,12 +391,21 @@ elif typ == 'PRIVMSG': if sender == 'freenode-connect': return - if target == self.nick: + if target.lower() == self.nick.lower(): self.on_privmsg(sender, msg) else: - if msg.startswith(self.nick+":"): + if msg.lower().startswith(self.nick.lower()+":"): text = msg.split(":", 1)[-1].strip() self.on_pubmsg(sender, text) + elif msg.lower().startswith(self.nick.lower()+">"): + text = msg.split(">", 1)[-1].strip() + self.on_pubmsg(sender, text) + elif msg.lower().startswith(self.nick.lower()+"]"): + text = msg.split("]", 1)[-1].strip() + self.on_pubmsg(sender, text) + elif msg.lower().startswith(self.nick.lower()+" "): + text = msg.split(" ", 1)[-1].strip() + self.on_pubmsg(sender, text) else: self.on_chanmsg(sender, target, msg) elif typ == 'QUIT': From zothar at freenetproject.org Thu Nov 30 21:59:22 2006 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Thu, 30 Nov 2006 21:59:22 +0000 (UTC) Subject: [Pyfreenet] r11153 - trunk/apps/pyFreenet Message-ID: <20061130215922.E15A09CA9F@emu.freenetproject.org> Author: zothar Date: 2006-11-30 21:59:19 +0000 (Thu, 30 Nov 2006) New Revision: 11153 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: Clean up some debugging. Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2006-11-30 21:52:21 UTC (rev 11152) +++ trunk/apps/pyFreenet/refbot.py 2006-11-30 21:59:19 UTC (rev 11153) @@ -664,20 +664,19 @@ return try: - f = fcp.FCPNode( host = self.fcp_host, port = self.fcp_port, verbosity = fcp.DETAIL ) + f = fcp.FCPNode( host = self.fcp_host, port = self.fcp_port ) if( have_plugin_module ): try: self.plugin_args[ "fcpNode" ] = f; self.plugin_args[ "ref" ] = ref_fieldset; plugin_result = botplugin.pre_add( self.plugin_args ); if( plugin_result != None ): - log("DEBUG: pre_add plugin rejected ref: would fail here **FIXME**: %s" % ( plugin_result )); self.status = -6 self.error_msg = plugin_result f.shutdown(); return except Exception, msg: - log("DEBUG: exception calling botplugin.pre_add(): %s" % ( msg )); + log("Got exception calling botplugin.pre_add(): %s" % ( msg )); noderef = f.refstats(); if( type( noderef ) == type( [] )): noderef = noderef[ 0 ]; @@ -744,7 +743,7 @@ try: plugin_result = botplugin.post_add( self.plugin_args ); except Exception, msg: - log("DEBUG: exception calling botplugin.post_add(): %s" % ( msg )); + log("Got exception calling botplugin.post_add(): %s" % ( msg )); try: 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() ) ) encoded_note_text = base64.encodestring( note_text ).replace( "\r", "" ).replace( "\n", "" ); From zothar at freenetproject.org Thu Nov 30 22:25:02 2006 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Thu, 30 Nov 2006 22:25:02 +0000 (UTC) Subject: [Pyfreenet] r11155 - trunk/apps/pyFreenet Message-ID: <20061130222502.27C069BD2E@emu.freenetproject.org> Author: zothar Date: 2006-11-30 22:24:58 +0000 (Thu, 30 Nov 2006) New Revision: 11155 Modified: trunk/apps/pyFreenet/minibot.py trunk/apps/pyFreenet/refbot.py Log: refbot: Get the node's identity once instead of for every ref adding attempt. Tweak the bot's nickserv identify process some more. Modified: trunk/apps/pyFreenet/minibot.py =================================================================== --- trunk/apps/pyFreenet/minibot.py 2006-11-30 22:01:19 UTC (rev 11154) +++ trunk/apps/pyFreenet/minibot.py 2006-11-30 22:24:58 UTC (rev 11155) @@ -196,7 +196,6 @@ self.after(1, self._sender) self.after(5, self._watchdog) #self.after(1, self._pinger) - self.after(5, self.identifyPassword) #@-node:connect #@+node:handlers @@ -216,7 +215,8 @@ return elif "End of /NAMES list" in msg: - #self.identifyPassword() # Don't identify twice (at least on freenode) + if(not self.hasIdentified): + self.after(5, self.identifyPassword) return elif typ == '353': @@ -237,21 +237,24 @@ return elif "If this is your nickname, type /msg NickServ" in msg: - self.identifyPassword() + self.after(1, self.identifyPassword) elif "The nickname " in msg and "is not registered" in msg: self.registerPassword() elif "Password accepted - you are now recognized" in msg: log("Password accepted") - self.hasIdentified = True - self.on_ready() - self.after(1, self._pinger) + if(not self.hasIdentified): + self.hasIdentified = True + self.on_ready() + self.after(1, self._pinger) elif "Your nickname is now registered" in msg: log("Password registered") - self.on_ready() - self.after(1, self._pinger) + if(not self.hasIdentified): + self.hasIdentified = True + self.on_ready() + self.after(1, self._pinger) #@-node:on_notice #@+node:on_ready Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2006-11-30 22:01:19 UTC (rev 11154) +++ trunk/apps/pyFreenet/refbot.py 2006-11-30 22:24:58 UTC (rev 11155) @@ -161,13 +161,21 @@ try: f = fcp.FCPNode( host = self.fcp_host, port = self.fcp_port ) + if( f.nodeBuild < self.minimumNodeBuild ): + print "This version of the refbot requires your node be running build %d or higher. Please upgrade your Freenet node and try again." % ( self.minimumNodeBuild ); + sys.exit( 1 ); + try: + noderef = f.refstats(); + if( type( noderef ) == type( [] )): + noderef = noderef[ 0 ]; + self.nodeIdentity = noderef[ "identity" ]; + except Exception, msg: + print "Failed to get the node's identity via FCP. This is an odd error this refbot developer is not sure of a reason for."; + sys.exit( 1 ); f.shutdown() except Exception, msg: print "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 ); sys.exit( 1 ); - if( f.nodeBuild < self.minimumNodeBuild ): - print "This version of the refbot requires your node be running build %d or higher. Please upgrade your Freenet node and try again." % ( self.minimumNodeBuild ); - sys.exit( 1 ); self.timeLastChanGreeting = time.time() self.haveSentDownloadLink = False @@ -374,7 +382,7 @@ def addref(self, url, replyfunc, sender_irc_nick): 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) + 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.adderThreads.append(adderThread) adderThread.start() @@ -616,7 +624,7 @@ #@-node:class RefBotConversation #@+node:class AddRef class AddRef(threading.Thread): - def __init__(self, tmci_host, tmci_port, fcp_host, fcp_port, url, replyfunc, sender_irc_nick, irc_host): + def __init__(self, tmci_host, tmci_port, fcp_host, fcp_port, url, replyfunc, sender_irc_nick, irc_host, nodeIdentity): threading.Thread.__init__(self) self.tmci_host = tmci_host self.tmci_port = tmci_port @@ -626,9 +634,10 @@ self.replyfunc = replyfunc self.sender_irc_nick = sender_irc_nick self.irc_host = irc_host + self.nodeIdentity = nodeIdentity 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 }; + 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 }; def run(self): try: @@ -656,6 +665,11 @@ continue; if(not ref_fieldset.has_key(reflinefields[ 0 ])): ref_fieldset[ reflinefields[ 0 ]] = reflinefields[ 1 ] + if( ref_fieldset[ "identity" ] == self.nodeIdentity ): + self.status = -5 + self.error_msg = "Node already has a ref with its own identity" + f.shutdown(); + return 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)): @@ -677,14 +691,10 @@ return except Exception, msg: log("Got exception calling botplugin.pre_add(): %s" % ( msg )); + # **FIXME** need to pass around the node identity that we get on start up noderef = f.refstats(); if( type( noderef ) == type( [] )): noderef = noderef[ 0 ]; - if( noderef[ "identity" ] == ref_fieldset[ "identity" ] ): - self.status = -5 - self.error_msg = "Node already has a ref with its own identity" - f.shutdown(); - return returned_peer = f.modifypeer( NodeIdentifier = ref_fieldset[ "identity" ] ) if( type( returned_peer ) == type( [] )): returned_peer = returned_peer[ 0 ];