Menu

Netlib NetLayer Implementations

Abstract: This page introduces all relevant Netlib NetLayer implementations. Each implementation is represented by a Java class that implements the NetLayer interface.

Introduction

This page introduces all relevant [Netlib NetLayer] implementations. Each implementation is represented by a Java class that implements the NetLayer interface.

NetLayer Implementations that implement Network Protocols

TcpipNetLayer

Plain TCP/IP network and transport layer - uses the JVM default SocketImpl implementation. The same as using original java.net.Socket.

TLSNetLayer

TLS/SSL transport layer protocol implementation.

SocksServerNetLayer

NetLayer that implements Socks4/Socks5 protocol to act as a proxy server.

SocksClientNetLayer

NetLayer that implements Socks5 protocol to act as a proxy client to access a Socks5 proxy server.

such a Socks5 proxy server can be, for instance, a SSH client as described here:

ssh -D 1080 user@remote.sshserver.com

TorNetLayer

Layer over Tor network: tunnels (TCP/IP) network traffic through the [Tor] anonymity network.

Details: [Netlib TorNetLayer]

NetLayer Implementations that implement specific Services

LoggingNetLayer

Transparent NetLayer that logs input streams and output streams. The connections/streams are forwarded to a lower NetLayer.

ControlNetLayer

Transparent NetLayer that enforces time(out) and throughput limits of a wrapped NetLayer. It aborts connections that hits the configured limits.

    // set control/timeout parameters: get default parameter set
    ControlParameters cp = ControlParameters.createTypicalFileTransferParameters()

    // set control/timeout parameters: set details: minimum throughput 5000 bytes/2 seconds
    cp.setThroughputTimeframeMinBytes(5000);
    cp.setThroughputTimeframeMillis(2000);

    // initialize NetLayer
    NetLayer lowerNetLayer = ...;
    ControlNetLayer wrapperNetLayer = new ControlNetLayer(lowerNetLayer, cp);

    ...

ForwardingNetLayer

NetLayer that forwards all connection requests to a lower layer and address specified in the constructor. Can be used e.g. to forward TCP/IP connections to a specified address/port.

SwitchingNetLayer

SwitchingNetLayer transparently forwards all traffic to a switchable/exchangeable lower NetLayer.

The method SwitchingNetLayer.setLowerNetLayer(NetLayer lowerNetLayer, boolean closeAllOpenConnectionsImmediately) is used to "switch".

ConditionalNetLayer

The ConditionalNetLayer transparently forwards all traffic to one of multiple lower NetLayer s. The selection depends on the specific IP/hostname/port number used when calling create(Server)Socket(). The constructor gets a list of conditions - these conditions determine which NetLayer instance should be used for which address.

Example: We want to define a NetLayer and use [Netlib Java Adapter] to forward all traffic to Tor, except the traffic to localhost/127.0.0.1 (Attention: such configuration can introduce a security whole and break the anonymity provided by TorNetLayer in some situations):

    // enable redirection (globally for the complete JVM)
    JvmGlobalUtil.init();

    // select the NetLayer implementation that should be used
    NetLayer torNetLayer = NetFactory.getInstance().getNetLayerById(NetLayerIDs.TOR);
    NetLayer tcpipNetLayer = NetFactory.getInstance().getNetLayerById(NetLayerIDs.TCPIP);
    NetLayer defaultNetLayer = torNetLayer;
    List<Condition> conditions = new ArrayList<Condition>();
        conditions.add(new Condition(new IpNetAddress("127.0.0.1"), tcpipNetLayer));
        conditions.add(new Condition("localhost", tcpipNetLayer));
    NetLayer netLayer = new ConditionalNetLayer(conditions, defaultNetLayer);

    // redirect to the selected netLayer and its corresponding name service implementation
    JvmGlobalUtil.setNetLayerAndNetAddressNameService(netLayer, true);

The Condition objects can be used even more flexible: you can specify regular expressions to match IP adresses or host names plus port number. Here are some examples:

        ...
        conditions.add(new Condition(Pattern.compile("99\\.88\\..+\\..+:\\d+"), tcpipNetLayer));
        conditions.add(new Condition(Pattern.compile("myspecialdomain\\.com:\\d+"), tcpipNetLayer));
        conditions.add(new Condition(Pattern.compile(".*\\.myspecialdomain\\.com:\\d+"), tcpipNetLayer));
        ...

NopNetLayer

No-Operation NetLayer does not allow creation of a new connection. Can be used together with the SwitchingNetLayer to temporarily prevent network connections.

MockNetLayer

Mock implementation, e.g. for testing.

EchoNetLayer

Echos output to input.

Used for educational purposes to demonstrate the NetSocket/NetLayer concept.


Top: [Netlib], Next: [Netlib TorNetLayer]


Related

Wiki: Netlib NetLayer
Wiki: Netlib

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.