@Override public void run() { try { handle(session); } catch (Exception e) { sessionManager.sessionOnException(session, e); // logger.error("SESSION[{}]: {}", session.getId(), e.getMessage()); } finally { session.close(); sessionManager.sessionOnClose(session); // logger.info("SESSION[{}] closed, {}", session.getId(), session.getNetworkMonitor().toString // ()); } }
/** * Calls {@link #newBuilder(Class)} with an argument <code>Socks5Handler.class</code>; * * @return Instance of {@link SocksServerBuilder}. */ public static SocksServerBuilder newSocks5ServerBuilder() { return new SocksServerBuilder(Socks5Handler.class); }
@Override public void addSessionListener(String name, SessionListener listener) { this.onCommand(name, listener); this.onException(name, listener); this.onSessionClose(name, listener); this.onSessionCreate(name, listener); }
@Override public void initializeSocksHandler(SocksHandler socksHandler) { socksHandler.setMethodSelector(methodSelector); socksHandler.setBufferSize(bufferSize); socksHandler.setProxy(proxy); socksHandler.setSocksProxyServer(this); }
@Override public void removeSessionListener(String name) { this.removeCommandListener(name); this.removeExceptionListener(name); this.removeSessionCloseListener(name); this.removeSessionCreateListener(name); }
@Override public Session newSession(Socket socket) { Session session = new SocksSession(++nextSessionId, socket, managedSessions); managedSessions.put(session.getId(), session); return session; }
/** * This method will save user in session. * * @param session Current session. * @param user user. */ protected void authenticationSuccess(Session session, User user) { session.setAttribute(USER_KEY, user); }
/** * Builds a {@link SocksProxyServer} which support SOCKS5 protocol. * This SOCKS5 server will accept all requests from clients with no authentication. * * @return Instance of {@link SocksProxyServer}. */ public static SocksProxyServer buildAnonymousSocks5Server() { return buildAnonymousSocks5Server(DEFAULT_PORT); }
/** * Creates a no authentication SOCKS5 server. The server will listen at port 1080. * * @return The instance of {@link SocksProxyServer} that supports SOCKS5 protocol. */ public static SocksProxyServer newNoAuthenticationServer() { return newNoAuthenticationServer(DEFAULT_PORT); }
/** * Shutdown SOCKS5 server. */ public void shutdown() { if (server != null) { server.shutdown(); } }
/** * Create a USERNAME/PASSWORD authentication SOCKS5 server. * * @param users Users. * @return The instance of {@link SocksProxyServer} that supports SOCKS5 protocol. */ public static SocksProxyServer newUsernamePasswordAuthenticationServer(User... users) { return newUsernamePasswordAuthenticationServer(DEFAULT_PORT, users); }
@Override public void run() { try { handle(session); } catch (Exception e) { sessionManager.sessionOnException(session, e); // logger.error("SESSION[{}]: {}", session.getId(), e.getMessage()); } finally { session.close(); sessionManager.sessionOnClose(session); // logger.info("SESSION[{}] closed, {}", session.getId(), session.getNetworkMonitor().toString // ()); } }
@Override public void addSessionListener(String name, SessionListener listener) { this.onCommand(name, listener); this.onException(name, listener); this.onSessionClose(name, listener); this.onSessionCreate(name, listener); }
@Override public void initializeSocksHandler(SocksHandler socksHandler) { socksHandler.setMethodSelector(methodSelector); socksHandler.setBufferSize(bufferSize); socksHandler.setProxy(proxy); socksHandler.setSocksProxyServer(this); }
@Override public void removeSessionListener(String name) { this.removeCommandListener(name); this.removeExceptionListener(name); this.removeSessionCloseListener(name); this.removeSessionCreateListener(name); }
/** * Calls {@link #newBuilder(Class)} with an argument <code>Socks5Handler.class</code>; * * @return Instance of {@link SocksServerBuilder}. */ public static SocksServerBuilder newSocks5ServerBuilder() { return new SocksServerBuilder(Socks5Handler.class); }
/** * This method will save user in session. * * @param session Current session. * @param user user. */ protected void authenticationSuccess(Session session, User user) { session.setAttribute(USER_KEY, user); }
/** * Builds a {@link SocksProxyServer} which support SOCKS5 protocol. * This SOCKS5 server will accept all requests from clients with no authentication. * * @return Instance of {@link SocksProxyServer}. */ public static SocksProxyServer buildAnonymousSocks5Server() { return buildAnonymousSocks5Server(DEFAULT_PORT); }
/** * Creates a no authentication SOCKS5 server. The server will listen at port 1080. * * @return The instance of {@link SocksProxyServer} that supports SOCKS5 protocol. */ public static SocksProxyServer newNoAuthenticationServer() { return newNoAuthenticationServer(DEFAULT_PORT); }
/** * Shutdown SOCKS5 server. */ public void shutdown() { if (server != null) { server.shutdown(); } }