1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec.socksx.v4;
17
18 import io.netty.handler.codec.DecoderResult;
19 import io.netty.util.internal.ObjectUtil;
20 import io.netty.util.internal.StringUtil;
21
22 import java.net.IDN;
23
24
25
26
27 public class DefaultSocks4CommandRequest extends AbstractSocks4Message implements Socks4CommandRequest {
28
29 private final Socks4CommandType type;
30 private final String dstAddr;
31 private final int dstPort;
32 private final String userId;
33
34
35
36
37
38
39
40
41 public DefaultSocks4CommandRequest(Socks4CommandType type, String dstAddr, int dstPort) {
42 this(type, dstAddr, dstPort, "");
43 }
44
45
46
47
48
49
50
51
52
53 public DefaultSocks4CommandRequest(Socks4CommandType type, String dstAddr, int dstPort, String userId) {
54 if (dstPort <= 0 || dstPort >= 65536) {
55 throw new IllegalArgumentException("dstPort: " + dstPort + " (expected: 1~65535)");
56 }
57 this.type = ObjectUtil.checkNotNull(type, "type");
58 this.dstAddr = IDN.toASCII(
59 ObjectUtil.checkNotNull(dstAddr, "dstAddr"));
60 this.userId = ObjectUtil.checkNotNull(userId, "userId");
61 this.dstPort = dstPort;
62 }
63
64 @Override
65 public Socks4CommandType type() {
66 return type;
67 }
68
69 @Override
70 public String dstAddr() {
71 return dstAddr;
72 }
73
74 @Override
75 public int dstPort() {
76 return dstPort;
77 }
78
79 @Override
80 public String userId() {
81 return userId;
82 }
83
84 @Override
85 public String toString() {
86 StringBuilder buf = new StringBuilder(128);
87 buf.append(StringUtil.simpleClassName(this));
88
89 DecoderResult decoderResult = decoderResult();
90 if (!decoderResult.isSuccess()) {
91 buf.append("(decoderResult: ");
92 buf.append(decoderResult);
93 buf.append(", type: ");
94 } else {
95 buf.append("(type: ");
96 }
97 buf.append(type());
98 buf.append(", dstAddr: ");
99 buf.append(dstAddr());
100 buf.append(", dstPort: ");
101 buf.append(dstPort());
102 buf.append(", userId: ");
103 buf.append(userId());
104 buf.append(')');
105
106 return buf.toString();
107 }
108 }