2016-01-01 17:44:11 -05:00
|
|
|
// Package proxy contains all proxies used by V2Ray.
|
2016-08-19 11:05:15 -04:00
|
|
|
package proxy
|
2016-01-01 17:44:11 -05:00
|
|
|
|
|
|
|
import (
|
2017-01-14 18:17:06 -05:00
|
|
|
"context"
|
|
|
|
|
2017-01-13 18:27:45 -05:00
|
|
|
"v2ray.com/core/common/net"
|
2016-08-20 14:55:45 -04:00
|
|
|
"v2ray.com/core/common/protocol"
|
|
|
|
"v2ray.com/core/transport/internet"
|
|
|
|
"v2ray.com/core/transport/ray"
|
2016-01-01 17:44:11 -05:00
|
|
|
)
|
|
|
|
|
2016-03-06 10:36:08 -05:00
|
|
|
type HandlerState int
|
|
|
|
|
|
|
|
const (
|
|
|
|
HandlerStateStopped = HandlerState(0)
|
|
|
|
HandlerStateRunning = HandlerState(1)
|
|
|
|
)
|
|
|
|
|
2016-08-14 11:08:01 -04:00
|
|
|
type SessionInfo struct {
|
2017-01-13 18:27:45 -05:00
|
|
|
Source net.Destination
|
|
|
|
Destination net.Destination
|
2016-08-14 11:08:01 -04:00
|
|
|
User *protocol.User
|
2016-11-13 08:33:00 -05:00
|
|
|
Inbound *InboundHandlerMeta
|
2016-08-14 11:08:01 -04:00
|
|
|
}
|
|
|
|
|
2016-06-04 08:25:13 -04:00
|
|
|
type InboundHandlerMeta struct {
|
2016-08-12 17:37:21 -04:00
|
|
|
Tag string
|
2017-01-13 18:27:45 -05:00
|
|
|
Address net.Address
|
|
|
|
Port net.Port
|
2016-08-12 17:37:21 -04:00
|
|
|
AllowPassiveConnection bool
|
2016-10-02 17:43:58 -04:00
|
|
|
StreamSettings *internet.StreamConfig
|
2016-06-04 08:25:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type OutboundHandlerMeta struct {
|
2016-06-14 16:54:08 -04:00
|
|
|
Tag string
|
2017-01-13 18:27:45 -05:00
|
|
|
Address net.Address
|
2016-10-02 17:43:58 -04:00
|
|
|
StreamSettings *internet.StreamConfig
|
2016-11-10 17:41:28 -05:00
|
|
|
ProxySettings *internet.ProxyConfig
|
|
|
|
}
|
|
|
|
|
2016-11-27 15:39:09 -05:00
|
|
|
func (v *OutboundHandlerMeta) GetDialerOptions() internet.DialerOptions {
|
2016-11-10 17:41:28 -05:00
|
|
|
return internet.DialerOptions{
|
2016-11-27 15:39:09 -05:00
|
|
|
Stream: v.StreamSettings,
|
|
|
|
Proxy: v.ProxySettings,
|
2016-11-10 17:41:28 -05:00
|
|
|
}
|
2016-06-04 08:25:13 -04:00
|
|
|
}
|
|
|
|
|
2016-01-25 15:33:28 -05:00
|
|
|
// An InboundHandler handles inbound network connections to V2Ray.
|
2016-01-25 11:18:24 -05:00
|
|
|
type InboundHandler interface {
|
2016-06-03 18:38:22 -04:00
|
|
|
// Listen starts a InboundHandler.
|
|
|
|
Start() error
|
2016-01-06 16:39:56 -05:00
|
|
|
// Close stops the handler to accepting anymore inbound connections.
|
2016-01-03 17:30:37 -05:00
|
|
|
Close()
|
2016-01-19 17:41:40 -05:00
|
|
|
// Port returns the port that the handler is listening on.
|
2017-01-13 18:27:45 -05:00
|
|
|
Port() net.Port
|
2016-01-01 17:44:11 -05:00
|
|
|
}
|
|
|
|
|
2016-01-25 15:33:28 -05:00
|
|
|
// An OutboundHandler handles outbound network connection for V2Ray.
|
2016-01-25 11:18:24 -05:00
|
|
|
type OutboundHandler interface {
|
2016-01-02 17:32:18 -05:00
|
|
|
// Dispatch sends one or more Packets to its destination.
|
2017-01-13 18:27:45 -05:00
|
|
|
Dispatch(destination net.Destination, ray ray.OutboundRay)
|
2016-01-01 17:44:11 -05:00
|
|
|
}
|
2017-01-14 18:17:06 -05:00
|
|
|
|
|
|
|
// Dialer is used by OutboundHandler for creating outbound connections.
|
|
|
|
type Dialer interface {
|
|
|
|
Dial(ctx context.Context, destination net.Destination) (internet.Connection, error)
|
|
|
|
}
|