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
           
 
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 addBroadcastAddress(InetAddress broadcastAddress)
          Adds an broadcast address.
 void 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()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

getAddresses

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

addBroadcastAddress

public Bindings addBroadcastAddress(InetAddress broadcastAddress)
Adds an broadcast address. This is used internally, but if you have Java 1.5, you may need to set this manually.

Parameters:
broadcastAddress - Adds a broadcast address used for pinging other peers on layer 2.
Returns:
The current class

getBroadcastAddresses

public List<InetAddress> getBroadcastAddresses()
Returns:
A list of broadcast addresses. If using Java 1.6, this is automatically filled.

addInterface

public void 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

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


Copyright © 2012. All Rights Reserved.