net.tomp2p.connection
Class Bindings

java.lang.Object
  extended by net.tomp2p.connection.Bindings

public class Bindings
extends Object

Gathers information about interface bindings. Here a user can set the preferences to which addresses to bind the socket. This class contains two types of information: 1.) the interface/address to listen for incoming connections and 2.) how other peers see us. The default is to listen to all interfaces and our outside address is set to the first interface it finds. If more than one search hint is used, then the combination operation will be "and"

Author:
Thomas Bocek

Nested Class Summary
static class Bindings.Protocol
          Types of protocols.
 
Field Summary
static int DEFAULT_PORT
          The default port of TomP2P
static int MAX_PORT
          aeu
static int MIN_DYN_PORT
          IANA recommends to use ports higher than 49152
 
Constructor Summary
Bindings()
          Creates a Binding class that binds to everything
Bindings(Bindings.Protocol protocol)
          Creates a Binding class that binds to a specified protocol
Bindings(Bindings.Protocol protocol, InetAddress externalAddress, int externalTCPPort, int externalUDPPort)
          Creates a Binding class that binds to a specified protocol and provides information about manual port forwarding
Bindings(Bindings.Protocol protocol, String iface)
          Creates a Binding class that binds to a specified protocol and interface
Bindings(Bindings.Protocol protocol, String iface, InetAddress bind)
          Creates a Binding class that binds to a specified protocol and interface and address
Bindings(InetAddress bind)
          Creates a Binding class that binds to a specified address
Bindings(InetAddress externalAddress, int externalTCPPort, int externalUDPPort)
          Creates a Binding class that binds to everything and provides information about manual port forwarding
Bindings(String iface)
          Creates a Binding class that binds to a specified interface
 
Method Summary
 Bindings add(Bindings other)
          Adds the results from an other binding.
 Bindings addAddress(InetAddress address)
          Adds an address that we want to listen to.
 Bindings addInterface(String interfaceHint)
          Adds an interface that will be searched for.
 void clear()
          Clears all lists: listenInterfaceHints, listenAddresses, broadcastAddresses.
 boolean containsInterface(String name)
          Checks if the user provided an interface hint
 List<InetAddress> getAddresses()
           
 List<InetAddress> getBroadcastAddresses()
           
 InetAddress getExternalAddress()
           
 List<InetAddress> getFoundAddresses()
          Returns a list of InetAddresses to listen to.
 List<String> getInterfaces()
           
 int getOutsideTCPPort()
           
 int getOutsideUDPPort()
           
 Bindings.Protocol getProtocol()
           
 boolean isAllAddresses()
           
 boolean isAllInterfaces()
           
 boolean isAllProtocols()
           
 boolean isExternalAddress()
           
 boolean isIPv4()
           
 boolean isIPv6()
           
 boolean isListenAll()
           
 boolean isSetExternalPortsManually()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_PORT

public static final int MAX_PORT
aeu

See Also:
Constant Field Values

MIN_DYN_PORT

public static final int MIN_DYN_PORT
IANA recommends to use ports higher than 49152

See Also:
Constant Field Values

DEFAULT_PORT

public static final int DEFAULT_PORT
The default port of TomP2P

See Also:
Constant Field Values
Constructor Detail

Bindings

public Bindings()
Creates a Binding class that binds to everything


Bindings

public Bindings(InetAddress bind)
Creates a Binding class that binds to a specified address

Parameters:
bind - The address to bind to

Bindings

public Bindings(String iface)
Creates a Binding class that binds to a specified interface

Parameters:
iface - The interface to bind to

Bindings

public Bindings(Bindings.Protocol protocol)
Creates a Binding class that binds to a specified protocol

Parameters:
protocol - The protocol to bind to

Bindings

public Bindings(Bindings.Protocol protocol,
                String iface)
Creates a Binding class that binds to a specified protocol and interface

Parameters:
protocol - The protocol to bind to
iface - The interface to bind to

Bindings

public Bindings(Bindings.Protocol protocol,
                String iface,
                InetAddress bind)
Creates a Binding class that binds to a specified protocol and interface and address

Parameters:
protocol - The protocol to bind to
iface - The interface to bind to
bind - The address to bind to

Bindings

public Bindings(InetAddress externalAddress,
                int externalTCPPort,
                int externalUDPPort)
Creates a Binding class that binds to everything and provides information about manual port forwarding

Parameters:
externalAddress - The external address, how other peers will see us
externalTCPPort - The external port, how other peers will see us
externalUDPPort - The external port, how other peers will see us

Bindings

public Bindings(Bindings.Protocol protocol,
                InetAddress externalAddress,
                int externalTCPPort,
                int externalUDPPort)
Creates a Binding class that binds to a specified protocol and provides information about manual port forwarding

Parameters:
protocol - The protocol to bind to
externalAddress - The external address, how other peers will see us. Use null if you don't want to use external address
externalTCPPort - The external port, how other peers will see us, if 0 is provided, a random port will be used
externalUDPPort - The external port, how other peers will see us, if 0 is provided, a random port will be used
Method Detail

getFoundAddresses

public List<InetAddress> getFoundAddresses()
Returns a list of InetAddresses to listen to. First Inet4Addresses, then Inet6Addresses are present in the list. This returns the matching addresses from DiscoverNetworks.

Returns:
A list of InetAddresses to listen to

addAddress

public Bindings addAddress(InetAddress address)
Adds an address that we want to listen to. If the address is not found, it will be ignored

Parameters:
address - The current class
Returns:
this instance

getAddresses

public List<InetAddress> getAddresses()
Returns:
A list of the addresses provided by the user

getBroadcastAddresses

public List<InetAddress> getBroadcastAddresses()
Returns:
A list of broadcast addresses.

addInterface

public Bindings addInterface(String interfaceHint)
Adds an interface that will be searched for. If the interface is not found, it will be ignored

Parameters:
interfaceHint - The interface, e.g. eth0
Returns:
The same instance

getInterfaces

public List<String> getInterfaces()
Returns:
A list of interfaces to listen to

getProtocol

public Bindings.Protocol getProtocol()
Returns:
The protocol to listen to

clear

public void clear()
Clears all lists: listenInterfaceHints, listenAddresses, broadcastAddresses.


isAllAddresses

public boolean isAllAddresses()
Returns:
Checks if the user sets any addresses

isAllInterfaces

public boolean isAllInterfaces()
Returns:
Checks if the user sets any interfaces

isAllProtocols

public boolean isAllProtocols()
Returns:
Checks if the user sets any protocols

isIPv4

public boolean isIPv4()
Returns:
Checks if the user sets protocol to anything or IPv4

isIPv6

public boolean isIPv6()
Returns:
Checks if the user sets protocol to anything or IPv6

isListenAll

public boolean isListenAll()
Returns:
Checks if the user sets anything at all

containsInterface

public boolean containsInterface(String name)
Checks if the user provided an interface hint

Parameters:
name - The name of the interface reported by the system
Returns:
True if the user added the interface

isExternalAddress

public boolean isExternalAddress()
Returns:
Checks if the user set the external address

getExternalAddress

public InetAddress getExternalAddress()
Returns:
Returns the externalAddress, how other peers see us

getOutsideTCPPort

public int getOutsideTCPPort()
Returns:
Returns the external port, how other peers see us

getOutsideUDPPort

public int getOutsideUDPPort()
Returns:
Returns the external port, how other peers see us

add

public Bindings add(Bindings other)
Adds the results from an other binding. This is useful because you can add within one Bindings hints only with "and", with add() you have the option "or" as well. E.g., Bindings b1 = new Bindings(IPv4, eth0); Bindings b2 = new Bindings(IPv6, eth1); b2.add(b1) -> this will bind to all IPv4 addresses on eth0 and all IPv6 addresses on eth1

Parameters:
other - The other instance to get the results from
Returns:
The same instance

isSetExternalPortsManually

public boolean isSetExternalPortsManually()
Returns:
True if the user specified both ports in advance. This tells us that the user knows about the ports and did a manual port-forwarding.


Copyright © 2013. All Rights Reserved.