| 
									
										
										
										
											2015-09-25 00:17:44 +02:00
										 |  |  | package protocol | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2015-10-13 13:55:06 +02:00
										 |  |  | 	"errors" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-08 23:06:12 +02:00
										 |  |  | 	"github.com/v2ray/v2ray-core/common/alloc" | 
					
						
							| 
									
										
										
										
											2015-12-02 20:44:01 +00:00
										 |  |  | 	v2net "github.com/v2ray/v2ray-core/common/net" | 
					
						
							| 
									
										
										
										
											2015-09-25 00:17:44 +02:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-13 13:55:06 +02:00
										 |  |  | var ( | 
					
						
							|  |  |  | 	Socks4Downgrade = errors.New("Downgraded to Socks 4.") | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2015-09-25 00:17:44 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | type Socks4AuthenticationRequest struct { | 
					
						
							|  |  |  | 	Version byte | 
					
						
							|  |  |  | 	Command byte | 
					
						
							| 
									
										
										
										
											2015-12-02 20:44:01 +00:00
										 |  |  | 	Port    v2net.Port | 
					
						
							| 
									
										
										
										
											2015-09-25 00:17:44 +02:00
										 |  |  | 	IP      [4]byte | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-09-25 17:59:45 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | type Socks4AuthenticationResponse struct { | 
					
						
							|  |  |  | 	result byte | 
					
						
							|  |  |  | 	port   uint16 | 
					
						
							|  |  |  | 	ip     []byte | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-02 20:44:01 +00:00
										 |  |  | func NewSocks4AuthenticationResponse(result byte, port v2net.Port, ip []byte) *Socks4AuthenticationResponse { | 
					
						
							| 
									
										
										
										
											2015-09-25 17:59:45 +02:00
										 |  |  | 	return &Socks4AuthenticationResponse{ | 
					
						
							|  |  |  | 		result: result, | 
					
						
							| 
									
										
										
										
											2015-12-02 20:44:01 +00:00
										 |  |  | 		port:   port.Value(), | 
					
						
							| 
									
										
										
										
											2015-09-25 17:59:45 +02:00
										 |  |  | 		ip:     ip, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-08 23:06:12 +02:00
										 |  |  | func (r *Socks4AuthenticationResponse) Write(buffer *alloc.Buffer) { | 
					
						
							|  |  |  | 	buffer.AppendBytes( | 
					
						
							|  |  |  | 		byte(0x00), r.result, byte(r.port>>8), byte(r.port), | 
					
						
							|  |  |  | 		r.ip[0], r.ip[1], r.ip[2], r.ip[3]) | 
					
						
							| 
									
										
										
										
											2015-09-25 17:59:45 +02:00
										 |  |  | } |