From 9071b3ea107a3b2db0f6481d0014cc303fc4bcf6 Mon Sep 17 00:00:00 2001 From: V2 Ray Date: Thu, 15 Oct 2015 11:15:59 +0000 Subject: [PATCH] more comments --- app/packet_dispatcher.go | 2 ++ common/log/log.go | 4 ++++ proxy/inbound_connection.go | 5 +++++ proxy/outbound_connection.go | 4 ++++ transport/ray/direct.go | 1 + 5 files changed, 16 insertions(+) diff --git a/app/packet_dispatcher.go b/app/packet_dispatcher.go index dba6bc39c..48dcf9e18 100644 --- a/app/packet_dispatcher.go +++ b/app/packet_dispatcher.go @@ -5,6 +5,8 @@ import ( "github.com/v2ray/v2ray-core/transport/ray" ) +// PacketDispatcher dispatch a packet and possibly further network payload to +// its destination. type PacketDispatcher interface { DispatchToOutbound(packet v2net.Packet) ray.InboundRay } diff --git a/common/log/log.go b/common/log/log.go index 0cff1a06c..786509e65 100644 --- a/common/log/log.go +++ b/common/log/log.go @@ -76,18 +76,22 @@ func SetLogLevel(level LogLevel) { } } +// Debug outputs a debug log with given format and optional arguments. func Debug(format string, v ...interface{}) { debugLogger.WriteLog("[Debug]", format, v...) } +// Info outputs an info log with given format and optional arguments. func Info(format string, v ...interface{}) { infoLogger.WriteLog("[Info]", format, v...) } +// Warning outputs a warning log with given format and optional arguments. func Warning(format string, v ...interface{}) { warningLogger.WriteLog("[Warning]", format, v...) } +// Error outputs an error log with given format and optional arguments. func Error(format string, v ...interface{}) { errorLogger.WriteLog("[Error]", format, v...) } diff --git a/proxy/inbound_connection.go b/proxy/inbound_connection.go index 5d6489612..2ad25595c 100644 --- a/proxy/inbound_connection.go +++ b/proxy/inbound_connection.go @@ -4,10 +4,15 @@ import ( "github.com/v2ray/v2ray-core/app" ) +// A InboundConnectionHandlerFactory creates InboundConnectionHandler on demand. type InboundConnectionHandlerFactory interface { + // Create creates a new InboundConnectionHandler with given configuration. Create(dispatch app.PacketDispatcher, config interface{}) (InboundConnectionHandler, error) } +// A InboundConnectionHandler handles inbound network connections to V2Ray. type InboundConnectionHandler interface { + // Listen starts a InboundConnectionHandler by listen on a specific port. This method is called + // exactly once during runtime. Listen(port uint16) error } diff --git a/proxy/outbound_connection.go b/proxy/outbound_connection.go index 3c8230cf3..67fd89964 100644 --- a/proxy/outbound_connection.go +++ b/proxy/outbound_connection.go @@ -5,10 +5,14 @@ import ( "github.com/v2ray/v2ray-core/transport/ray" ) +// An OutboundConnectionHandlerFactory creates OutboundConnectionHandler on demand. type OutboundConnectionHandlerFactory interface { + // Create creates a new OutboundConnectionHandler with given config. Create(config interface{}) (OutboundConnectionHandler, error) } +// An OutboundConnectionHandler handles outbound network connection for V2Ray. type OutboundConnectionHandler interface { + // Dispatch sends one or more Packets to its destination. Dispatch(firstPacket v2net.Packet, ray ray.OutboundRay) error } diff --git a/transport/ray/direct.go b/transport/ray/direct.go index b70a0c465..88c36ab82 100644 --- a/transport/ray/direct.go +++ b/transport/ray/direct.go @@ -8,6 +8,7 @@ const ( bufferSize = 16 ) +// NewRay creates a new Ray for direct traffic transport. func NewRay() Ray { return &directRay{ Input: make(chan *alloc.Buffer, bufferSize),