/** * Constructs an instance of {@link MethodSelectionResponseMessage} with a version and a method. * * @param version Version. * @param socksMethod Selected method. */ public MethodSelectionResponseMessage(int version, SocksMethod socksMethod) { this(version, socksMethod.getByte()); }
/** * Constructs an instance of {@link MethodSelectionResponseMessage} with a version and a method. * * @param version Version. * @param socksMethod Selected method. */ public MethodSelectionResponseMessage(int version, SocksMethod socksMethod) { this(version, socksMethod.getByte()); }
/** * Constructs an instance of {@link MethodSelectionResponseMessage} with a method. * * @param socksMethod Selected method. */ public MethodSelectionResponseMessage(SocksMethod socksMethod) { this(5, socksMethod.getByte()); }
/** * Constructs an instance of {@link MethodSelectionResponseMessage} with a method. * * @param socksMethod Selected method. */ public MethodSelectionResponseMessage(SocksMethod socksMethod) { this(5, socksMethod.getByte()); }
/** * Puts a {@link SocksMethod} class into the SOCKS method registry with an instance of * {@link SocksMethod}. * * @param socksMethod The instance of {@link SocksMethod}. */ public static void putMethod(SocksMethod socksMethod) { checkNotNull(socksMethod, "Argument [socksMethod] may not be null"); logger.debug("Register {}[{}]", socksMethod.getMethodName(), socksMethod.getByte()); methods.put((byte) socksMethod.getByte(), socksMethod); }
/** * Puts a {@link SocksMethod} class into the SOCKS method registry with an instance of * {@link SocksMethod}. * * @param socksMethod The instance of {@link SocksMethod}. */ public static void putMethod(SocksMethod socksMethod) { checkNotNull(socksMethod, "Argument [socksMethod] may not be null"); logger.debug("Register {}[{}]", socksMethod.getMethodName(), socksMethod.getByte()); methods.put((byte) socksMethod.getByte(), socksMethod); }
@Override public boolean equals(Object obj) { return obj instanceof SocksMethod && ((SocksMethod) obj).getByte() == this.getByte(); }
@Override public boolean equals(Object obj) { return obj instanceof SocksMethod && ((SocksMethod) obj).getByte() == this.getByte(); }
@Override public SocksMethod select(MethodSelectionMessage message) { int[] methods = message.getMethods(); for (int i = 0; i < methods.length; i++) { for (SocksMethod method : supportMethods) { if (method.getByte() == methods[i]) { return method; } } } return new NoAcceptableMethod(); }
@Override public SocksMethod select(MethodSelectionMessage message) { int[] methods = message.getMethods(); for (int i = 0; i < methods.length; i++) { for (SocksMethod method : supportMethods) { if (method.getByte() == methods[i]) { return method; } } } return new NoAcceptableMethod(); }
@Override public SocksMethod doRequest(List<SocksMethod> acceptableMethods, Socket socket, int socksVersion) throws SocksException, IOException { InputStream inputStream = socket.getInputStream(); OutputStream outputStream = socket.getOutputStream(); byte[] bufferSent = new byte[2 + acceptableMethods.size()]; bufferSent[0] = (byte) socksVersion; bufferSent[1] = (byte) acceptableMethods.size(); for (int i = 0; i < acceptableMethods.size(); i++) { bufferSent[2 + i] = (byte) acceptableMethods.get(i).getByte(); } outputStream.write(bufferSent); outputStream.flush(); logger.debug("{}", LogMessageBuilder.build(bufferSent, MsgType.SEND)); // Received data. byte[] receivedData = StreamUtil.read(inputStream, 2); logger.debug("{}", LogMessageBuilder.build(receivedData, MsgType.RECEIVE)); if (receivedData[0] != socksVersion) { throw new SocksException("Remote server don't support SOCKS5"); } return SocksMethodRegistry.getByByte(receivedData[1]); }
@Override public SocksMethod doRequest(List<SocksMethod> acceptableMethods, Socket socket, int socksVersion) throws SocksException, IOException { InputStream inputStream = socket.getInputStream(); OutputStream outputStream = socket.getOutputStream(); byte[] bufferSent = new byte[2 + acceptableMethods.size()]; bufferSent[0] = (byte) socksVersion; bufferSent[1] = (byte) acceptableMethods.size(); for (int i = 0; i < acceptableMethods.size(); i++) { bufferSent[2 + i] = (byte) acceptableMethods.get(i).getByte(); } outputStream.write(bufferSent); outputStream.flush(); logger.debug("{}", LogMessageBuilder.build(bufferSent, MsgType.SEND)); // Received data. byte[] receivedData = StreamUtil.read(inputStream, 2); logger.debug("{}", LogMessageBuilder.build(receivedData, MsgType.RECEIVE)); if (receivedData[0] != socksVersion) { throw new SocksException("Remote server don't support SOCKS5"); } return SocksMethodRegistry.getByByte(receivedData[1]); }