[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[vidalia-svn] r1797: Add support for ADDRMAP events. (trunk/src/control)



Author: edmanm
Date: 2007-07-02 21:30:35 -0400 (Mon, 02 Jul 2007)
New Revision: 1797

Added:
   trunk/src/control/addressmapevent.h
Modified:
   trunk/src/control/eventtype.h
   trunk/src/control/torevents.cpp
   trunk/src/control/torevents.h
Log:
Add support for ADDRMAP events.


Added: trunk/src/control/addressmapevent.h
===================================================================
--- trunk/src/control/addressmapevent.h	                        (rev 0)
+++ trunk/src/control/addressmapevent.h	2007-07-03 01:30:35 UTC (rev 1797)
@@ -0,0 +1,62 @@
+/****************************************************************
+ *  Vidalia is distributed under the following license:
+ *
+ *  Copyright (C) 2007,  Matt Edman, Justin Hipple
+ *
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License
+ *  as published by the Free Software Foundation; either version 2
+ *  of the License, or (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, 
+ *  Boston, MA  02110-1301, USA.
+  ****************************************************************/
+
+/** 
+ * \file addressmapevent.h
+ * \version $Id: bandwidthevent.h 1563 2006-12-26 06:06:04Z edmanm $
+ * \brief Event dispatched upon receiving a new or updated address mapping
+ * from Tor.
+ */
+
+#ifndef _ADDRESSMAPEVENT_H
+#define _ADDRESSMAPEVENT_H
+
+#include <QEvent>
+#include <QString>
+#include <QDateTime>
+
+
+class AddressMapEvent : public QEvent
+{
+public:
+  /** Constructor */
+  AddressMapEvent(QString from, QString to, QDateTime expires)
+  : QEvent((QEvent::Type)CustomEventType::AddressMapEvent)
+  { _from = from; _to = to; _expires = expires; }
+
+  /** Returns the number of bytes read in the last second */
+  QString from() const { return _from; }
+  /** Returns the number of bytes written in the last second */
+  QString to() const { return _to; }
+  /** Returns the date and time at which this mapping should expire, in local
+   * time. */
+  QDateTime expires() const { return _expires; }
+  /** Returns true if this address mapping is expired. */
+  bool isExpired() const { return (_expires > QDateTime::currentDateTime()); }
+
+private:
+  QString _from; /**< The source address of this mapping. */
+  QString _to;   /**< The target address of this mapping. */
+  QDateTime _expires; /**< The time at which this mapping expires (if ever). */
+};
+
+#endif
+

Modified: trunk/src/control/eventtype.h
===================================================================
--- trunk/src/control/eventtype.h	2007-07-03 01:28:52 UTC (rev 1796)
+++ trunk/src/control/eventtype.h	2007-07-03 01:30:35 UTC (rev 1797)
@@ -47,6 +47,8 @@
   const int NewDescriptorEvent = QEvent::User+5;
   /** Control command send event. */
   const int SendCommandEvent   = QEvent::User+6;
+  /** New address mapping event. */
+  const int AddressMapEvent = QEvent::User+7;
 }
 
 #endif

Modified: trunk/src/control/torevents.cpp
===================================================================
--- trunk/src/control/torevents.cpp	2007-07-03 01:28:52 UTC (rev 1796)
+++ trunk/src/control/torevents.cpp	2007-07-03 01:30:35 UTC (rev 1797)
@@ -27,11 +27,16 @@
 
 #include <QApplication>
 
+#include <vidalia.h>
+
 #include "circuit.h"
 #include "stream.h"
 #include "torevents.h"
 
+/** Format of expiry times in address map events. */
+#define DATE_FMT "\"yyyy-MM-dd HH:mm:ss\""
 
+
 /** Default constructor */
 TorEvents::TorEvents()
 {
@@ -102,6 +107,7 @@
     case StreamStatus:    event = "STREAM"; break;
     case OrConnStatus:    event = "ORCONN"; break;
     case NewDescriptor:   event = "NEWDESC"; break;
+    case AddressMap:      event = "ADDRMAP"; break;
     default: event = "UNKNOWN"; break;
   }
   return event;
@@ -149,6 +155,8 @@
     e = OrConnStatus;
   } else if (event == "NEWDESC") {
     e = NewDescriptor;
+  } else if (event == "ADDRMAP") {
+    e = AddressMap;
   } else {
     e = Unknown;
   }
@@ -178,6 +186,7 @@
       case StreamStatus:   handleStreamStatus(line); break;
       case OrConnStatus:   handleOrConnStatus(line); break;
       case NewDescriptor:  handleNewDescriptor(line); break;
+      case AddressMap:     handleAddressMap(line); break;
 
       case LogDebug: 
       case LogInfo:
@@ -318,3 +327,23 @@
   }
 }
 
+/** Handles a new or updated address mapping event. The format for event
+ * messages of this type is:
+ *
+ *   "650" SP "ADDRMAP" SP Address SP Address SP Expiry
+ *   Expiry = DQUOTE ISOTime DQUOTE / "NEVER"
+ *
+ *   Expiry is expressed as the local time (rather than GMT).
+ */
+void
+TorEvents::handleAddressMap(ReplyLine line)
+{
+  QStringList msg = line.getMessage().split(" ");
+  if (msg.size() >= 4) {
+    QDateTime expires;
+    if (msg.size() >= 5 && msg.at(3) != "NEVER")
+      expires = QDateTime::fromString(msg.at(3) + " " + msg.at(4), DATE_FMT);
+    dispatch(AddressMap, new AddressMapEvent(msg.at(1), msg.at(2), expires));
+  }
+}
+

Modified: trunk/src/control/torevents.h
===================================================================
--- trunk/src/control/torevents.h	2007-07-03 01:28:52 UTC (rev 1796)
+++ trunk/src/control/torevents.h	2007-07-03 01:30:35 UTC (rev 1797)
@@ -39,7 +39,7 @@
 #include "streamevent.h"
 #include "orconnevent.h"
 #include "newdescriptorevent.h"
-
+#include "addressmapevent.h"
 #include "controlreply.h"
 
 
@@ -56,7 +56,8 @@
     CircuitStatus,
     StreamStatus,
     OrConnStatus,
-    NewDescriptor
+    NewDescriptor,
+    AddressMap
   };
  
   /** Default Constructor */
@@ -106,6 +107,8 @@
   void handleOrConnStatus(ReplyLine line);
   /** Handles a new list of descriptors event. */
   void handleNewDescriptor(ReplyLine line);
+  /** Handles a new or updated address map event. */
+  void handleAddressMap(ReplyLine line);
 };
 
 #endif