コード例 #1
0
ファイル: server.go プロジェクト: xyz12810/v2ray-core
func (this *Server) Start() error {
	if this.accepting {
		return nil
	}

	tcpHub, err := internet.ListenTCP(this.meta.Address, this.meta.Port, this.handleConnection, this.meta.StreamSettings)
	if err != nil {
		log.Error("Shadowsocks: Failed to listen TCP on ", this.meta.Address, ":", this.meta.Port, ": ", err)
		return err
	}
	this.tcpHub = tcpHub

	if this.config.UdpEnabled {
		this.udpServer = udp.NewUDPServer(this.packetDispatcher)
		udpHub, err := udp.ListenUDP(this.meta.Address, this.meta.Port, udp.ListenOption{Callback: this.handlerUDPPayload})
		if err != nil {
			log.Error("Shadowsocks: Failed to listen UDP on ", this.meta.Address, ":", this.meta.Port, ": ", err)
			return err
		}
		this.udpHub = udpHub
	}

	this.accepting = true

	return nil
}
コード例 #2
0
ファイル: nameserver.go プロジェクト: v2ray/v2ray-core
func NewUDPNameServer(address v2net.Destination, dispatcher dispatcher.PacketDispatcher) *UDPNameServer {
	s := &UDPNameServer{
		address:   address,
		requests:  make(map[uint16]*PendingRequest),
		udpServer: udp.NewUDPServer(dispatcher),
	}
	return s
}
コード例 #3
0
ファイル: nameserver.go プロジェクト: DZLZHCODE/v2ray-core
func NewUDPNameServer(address v2net.Destination, dispatcher dispatcher.PacketDispatcher) *UDPNameServer {
	s := &UDPNameServer{
		address:  address,
		requests: make(map[uint16]*PendingRequest),
		udpServer: udp.NewUDPServer(&proxy.InboundHandlerMeta{
			AllowPassiveConnection: false,
		}, dispatcher),
	}
	return s
}
コード例 #4
0
ファイル: server_udp.go プロジェクト: DZLZHCODE/v2ray-core
func (this *Server) listenUDP() error {
	this.udpServer = udp.NewUDPServer(this.meta, this.packetDispatcher)
	udpHub, err := udp.ListenUDP(this.meta.Address, this.meta.Port, udp.ListenOption{Callback: this.handleUDPPayload})
	if err != nil {
		log.Error("Socks: Failed to listen on udp ", this.meta.Address, ":", this.meta.Port)
		return err
	}
	this.udpMutex.Lock()
	this.udpAddress = v2net.UDPDestination(this.config.Address, this.meta.Port)
	this.udpHub = udpHub
	this.udpMutex.Unlock()
	return nil
}
コード例 #5
0
ファイル: server_udp.go プロジェクト: v2ray/v2ray-core
func (v *Server) listenUDP() error {
	v.udpServer = udp.NewUDPServer(v.packetDispatcher)
	udpHub, err := udp.ListenUDP(v.meta.Address, v.meta.Port, udp.ListenOption{Callback: v.handleUDPPayload})
	if err != nil {
		log.Error("Socks: Failed to listen on udp (", v.meta.Address, ":", v.meta.Port, "): ", err)
		return err
	}
	v.udpMutex.Lock()
	v.udpAddress = v2net.UDPDestination(v.config.GetNetAddress(), v.meta.Port)
	v.udpHub = udpHub
	v.udpMutex.Unlock()
	return nil
}
コード例 #6
0
ファイル: dokodemo.go プロジェクト: DZLZHCODE/v2ray-core
func (this *DokodemoDoor) ListenUDP() error {
	this.udpServer = udp.NewUDPServer(this.meta, this.packetDispatcher)
	udpHub, err := udp.ListenUDP(
		this.meta.Address, this.meta.Port, udp.ListenOption{
			Callback:            this.handleUDPPackets,
			ReceiveOriginalDest: this.config.FollowRedirect,
		})
	if err != nil {
		log.Error("Dokodemo failed to listen on ", this.meta.Address, ":", this.meta.Port, ": ", err)
		return err
	}
	this.udpMutex.Lock()
	this.udpHub = udpHub
	this.udpMutex.Unlock()
	return nil
}
コード例 #7
0
ファイル: dokodemo.go プロジェクト: v2ray/v2ray-core
func (v *DokodemoDoor) ListenUDP() error {
	v.udpServer = udp.NewUDPServer(v.packetDispatcher)
	udpHub, err := udp.ListenUDP(
		v.meta.Address, v.meta.Port, udp.ListenOption{
			Callback:            v.handleUDPPackets,
			ReceiveOriginalDest: v.config.FollowRedirect,
			Concurrency:         2,
		})
	if err != nil {
		log.Error("Dokodemo failed to listen on ", v.meta.Address, ":", v.meta.Port, ": ", err)
		return err
	}
	v.udpMutex.Lock()
	v.udpHub = udpHub
	v.udpMutex.Unlock()
	return nil
}