
org.silvertunnel_ng.netlib.layer.control.ControlNetLayer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of netlib Show documentation
Show all versions of netlib Show documentation
SilverTunnel-NG Netlib is a free library for the Java programming language that implements and
encapsulates all the complex network protocol stuff needed for anonymous communication over the Tor anonymity
network. Netlib can be easily integrated in almost every existing and new Java application. The library requires
Java 1.6/Java SE 6 or a newer version.
The original silvertunnel Netlib can be found here : silvertunnel.org
The newest version!
/*
* silvertunnel.org Netlib - Java library to easily access anonymity networks
* Copyright (c) 2009-2012 silvertunnel.org
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see .
*/
package org.silvertunnel_ng.netlib.layer.control;
import org.silvertunnel_ng.netlib.api.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Map;
/**
* Transparent NetLayer that enforces time(out) and throughput limits of a
* wrapped NetLayer. It aborts connections that hits the configured limits.
*
* @author hapke
*/
public class ControlNetLayer implements NetLayer {
/** */
private static final Logger LOG = LoggerFactory.getLogger(ControlNetLayer.class);
private final NetLayer lowerNetLayer;
private final ControlParameters controlParameters;
/**
* Initialize a new layer.
*
* @param lowerNetLayer
* @param controlParameters definition when to terminate a connection
*/
public ControlNetLayer(final NetLayer lowerNetLayer,
final ControlParameters controlParameters) {
this.lowerNetLayer = lowerNetLayer;
this.controlParameters = controlParameters;
}
@Override
public NetSocket createNetSocket(NetAddress remoteAddress) throws IOException {
return new ControlNetSocket(lowerNetLayer.createNetSocket(remoteAddress),
controlParameters);
}
/**
* @see NetLayer#createNetSocket(Map, NetAddress, NetAddress)
*/
@Override
public NetSocket createNetSocket(final Map localProperties,
final NetAddress localAddress, final NetAddress remoteAddress)
throws IOException {
return new ControlNetSocket(lowerNetLayer.createNetSocket(
localProperties, localAddress, remoteAddress),
controlParameters);
}
/**
* @see NetLayer#createNetServerSocket(Map, NetAddress)
*/
@Override
public NetServerSocket createNetServerSocket(
final Map properties,
final NetAddress localListenAddress) throws IOException {
throw new UnsupportedOperationException();
}
@Override
public void clear() throws IOException {
lowerNetLayer.clear();
}
@Override
public NetAddressNameService getNetAddressNameService() {
return lowerNetLayer.getNetAddressNameService();
}
@Override
public void close() {
// nothing to do
}
@Override
public NetLayerStatus getStatus() {
return lowerNetLayer.getStatus();
}
@Override
public void waitUntilReady() {
lowerNetLayer.waitUntilReady();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy