Author: toad
Date: 2007-09-07 15:34:12 +0000 (Fri, 07 Sep 2007)
New Revision: 14999

Added:
   trunk/freenet/src/freenet/pluginmanager/ForwardPort.java
   trunk/freenet/src/freenet/pluginmanager/ForwardPortCallback.java
   trunk/freenet/src/freenet/pluginmanager/ForwardPortStatus.java
   trunk/freenet/src/freenet/pluginmanager/FredPluginPortForward.java
Log:
Better (heavier, maybe too heavy) port forwarding plugin interfaces

Added: trunk/freenet/src/freenet/pluginmanager/ForwardPort.java
===================================================================
--- trunk/freenet/src/freenet/pluginmanager/ForwardPort.java                    
        (rev 0)
+++ trunk/freenet/src/freenet/pluginmanager/ForwardPort.java    2007-09-07 
15:34:12 UTC (rev 14999)
@@ -0,0 +1,30 @@
+package freenet.pluginmanager;
+
+/**
+ * A public Internet Protocol port on the node which needs to be forwarded if 
the
+ * node is NATed.
+ * @author toad
+ */
+public class ForwardPort {
+
+       /** Name of the interface e.g. "opennet" */
+       public final String name;
+       /** IPv4 vs IPv6? */
+       public final boolean isIP6;
+       /** Protocol number. See constants. */
+       public final int protocol;
+       public static final int PROTOCOL_UDP_IPV4 = 17;
+       public static final int PROTOCOL_TCP_IPV4 = 6;
+       /** Port number to forward */
+       public final int portNumber;
+       // We don't currently support binding to a specific internal interface.
+       // It would be complicated: Different interfaces may be on different 
LANs,
+       // and an IGD is normally on only one LAN.
+       
+       public ForwardPort(String name, boolean isIP6, int protocol, int 
portNumber) {
+               this.name = name;
+               this.isIP6 = isIP6;
+               this.protocol = protocol;
+               this.portNumber = portNumber;
+       }
+}

Added: trunk/freenet/src/freenet/pluginmanager/ForwardPortCallback.java
===================================================================
--- trunk/freenet/src/freenet/pluginmanager/ForwardPortCallback.java            
                (rev 0)
+++ trunk/freenet/src/freenet/pluginmanager/ForwardPortCallback.java    
2007-09-07 15:34:12 UTC (rev 14999)
@@ -0,0 +1,14 @@
+package freenet.pluginmanager;
+
+import java.util.Map;
+
+/**
+ * Callback called by port forwarding plugins to indicate success or failure.
+ * @author toad
+ */
+public interface ForwardPortCallback {
+       
+       /** Called to indicate status on one or more forwarded ports. */
+       public void status(Map /*<ForwardPort,ForwardPortStatus>*/ statuses);
+
+}

Added: trunk/freenet/src/freenet/pluginmanager/ForwardPortStatus.java
===================================================================
--- trunk/freenet/src/freenet/pluginmanager/ForwardPortStatus.java              
                (rev 0)
+++ trunk/freenet/src/freenet/pluginmanager/ForwardPortStatus.java      
2007-09-07 15:34:12 UTC (rev 14999)
@@ -0,0 +1,28 @@
+package freenet.pluginmanager;
+
+public class ForwardPortStatus {
+       
+       public final int status;
+       /** The port forward is in progress */
+       public static final int IN_PROGRESS = 0;
+       /** The port forward definitely succeeded. */
+       public static final int DEFINITE_SUCCESS = 1;
+       /** The port forward probably succeeded. I.e. it succeeded unless there 
was
+        * for example hostile action on the part of the router. */
+       public static final int PROBABLE_SUCCESS = 2;
+       /** The port forward may have succeeded. Or it may not have. We should 
+        * definitely try to check out of band. See UP&P: Many routers say 
they've
+        * forwarded the port when they haven't. */
+       public static final int MAYBE_SUCCESS = 3;
+       /** The port forward definitely failed. */
+       public static final int DEFINITE_FAILURE = -1;
+       /** The port forward probably failed */
+       public static final int PROBABLE_FAILURE = -2;
+       
+       public final String reasonString;
+       
+       public ForwardPortStatus(int status, String reason) {
+               this.status = status;
+               this.reasonString = reason;
+       }
+}

Added: trunk/freenet/src/freenet/pluginmanager/FredPluginPortForward.java
===================================================================
--- trunk/freenet/src/freenet/pluginmanager/FredPluginPortForward.java          
                (rev 0)
+++ trunk/freenet/src/freenet/pluginmanager/FredPluginPortForward.java  
2007-09-07 15:34:12 UTC (rev 14999)
@@ -0,0 +1,21 @@
+package freenet.pluginmanager;
+
+import java.util.Set;
+
+/**
+ * Interface for port forwarding plugins.
+ * @author toad
+ */
+public interface FredPluginPortForward {
+
+       /**
+        * Called when Fred's list of public ports changes, and just after 
loading the
+        * plugin.
+        * @param ports The set of ports that need to be forwarded from the 
outside 
+        * world through the NAT or firewall.
+        * @param cb Callback to be called with success/failure of each 
forward. Some
+        * plugins may return a probabilistic success e.g. with UP&P.
+        */
+       public void onChangePublicPorts(Set/*<ForwardPort>*/ ports, 
ForwardPortCallback cb);
+       
+}


Reply via email to