Class PcpPortMapping

java.lang.Object
org.drasyl.handler.remote.portmapper.PcpPortMapping
All Implemented Interfaces:
PortMapping

public class PcpPortMapping extends Object implements PortMapping
Port Forwarding on NAT-enabled routers via PCP.

This methods requires the following steps:

  • identify own default network gateway
  • send mapping request to gateway for every local network address
  • gateway should only create mapping for local network address it belongs to
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Duration
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    acceptMessage(InetSocketAddress sender, io.netty.buffer.ByteBuf msg)
    Is called for incoming messages and returns true if the message should be consumed and removed from the pipeline.
    void
    handleMessage(io.netty.channel.ChannelHandlerContext ctx, InetSocketAddress sender, io.netty.buffer.ByteBuf msg)
    Is called for incoming messages and thus enables this method to react to relevant messages.
    void
    start(io.netty.channel.ChannelHandlerContext ctx, int port, Runnable onFailure)
    Tells the method to create a port forwarding and renew it independently.
    void
    stop(io.netty.channel.ChannelHandlerContext ctx)
    Shall remove any existing port forwarding again.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • TIMEOUT

      public static final Duration TIMEOUT
  • Constructor Details

    • PcpPortMapping

      public PcpPortMapping()
  • Method Details

    • start

      public void start(io.netty.channel.ChannelHandlerContext ctx, int port, Runnable onFailure)
      Description copied from interface: PortMapping
      Tells the method to create a port forwarding and renew it independently. If no forwarding can be created, onFailure must be called once.
      Specified by:
      start in interface PortMapping
      Parameters:
      ctx - the handler context
      port - the UdpServer.Port port
      onFailure - will be called once on failure
    • stop

      public void stop(io.netty.channel.ChannelHandlerContext ctx)
      Description copied from interface: PortMapping
      Shall remove any existing port forwarding again.
      Specified by:
      stop in interface PortMapping
      Parameters:
      ctx - the handler context
    • acceptMessage

      public boolean acceptMessage(InetSocketAddress sender, io.netty.buffer.ByteBuf msg)
      Description copied from interface: PortMapping
      Is called for incoming messages and returns true if the message should be consumed and removed from the pipeline.
      Specified by:
      acceptMessage in interface PortMapping
      Parameters:
      sender - the sender of the message
      msg - the message
      Returns:
      true if the message is relevant for the current port forwarding method. Otherwise false
    • handleMessage

      public void handleMessage(io.netty.channel.ChannelHandlerContext ctx, InetSocketAddress sender, io.netty.buffer.ByteBuf msg)
      Description copied from interface: PortMapping
      Is called for incoming messages and thus enables this method to react to relevant messages.

      ReferenceCounted.release() ownership of msg is transferred to this PartialReadMessage.

      Specified by:
      handleMessage in interface PortMapping
      Parameters:
      ctx - the handler context
      sender - the sender of the message
      msg - the message
    • toString

      public String toString()
      Overrides:
      toString in class Object