org.apache.log4j.Logger.getRootLogger().setLevel(Level.toLevel(
cli.getOptionValue("loglevel", "INFO")));
NioDatagramAcceptor acceptor = new NioDatagramAcceptor();
final SwitchHandler handler = new SwitchHandler(acceptor);
acceptor.setHandler(handler);
DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
LoggingFilter loggingFilter = new LoggingFilter();
loggingFilter.setMessageReceivedLogLevel(LogLevel.TRACE);
loggingFilter.setMessageSentLogLevel(LogLevel.TRACE);
chain.addLast("logger", loggingFilter);
DatagramSessionConfig dcfg = acceptor.getSessionConfig();
dcfg.setReuseAddress(true);
acceptor.addListener(new IoServiceListener() {
@Override
public void sessionDestroyed(IoSession session) throws Exception {
}
@Override
public void sessionCreated(IoSession session) throws Exception {
}
@Override
public void serviceIdle(IoService service, IdleStatus idleStatus)
throws Exception {
}
@Override
public void serviceDeactivated(IoService service) throws Exception {
}
@Override
public void serviceActivated(IoService service) throws Exception {
InetSocketAddress seedAddr =
(InetSocketAddress) TelehashFactory.eINSTANCE
.createFromString(TelehashPackage.Literals.ENDPOINT,
cli.getOptionValue("seed", "telehash.org:42424"));
handler.seed(seedAddr);
}
});
Integer port = Integer.parseInt(cli.getOptionValue("port", "0"));
InetSocketAddress bindAddress = new InetSocketAddress(port);