From 5de7fb8bc25241e1ed9ba87a8c19e0984377b90c Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Wed, 8 Feb 2017 10:01:22 +0100 Subject: [PATCH] comments --- common/errors/errors.go | 13 +++++++++++-- common/net/address.proto | 3 ++- common/net/destination.go | 2 +- common/net/destination.proto | 1 + common/net/network.proto | 4 ---- common/net/port.proto | 2 ++ 6 files changed, 17 insertions(+), 8 deletions(-) diff --git a/common/errors/errors.go b/common/errors/errors.go index a33ab981..e5ff29b3 100644 --- a/common/errors/errors.go +++ b/common/errors/errors.go @@ -1,3 +1,4 @@ +// Package errors is a drop-in replacement for Golang lib 'errors'. package errors import ( @@ -6,19 +7,23 @@ import ( "v2ray.com/core/common/serial" ) -type HasInnerError interface { +type hasInnerError interface { + // Inner returns the underlying error of this one. Inner() error } +// Error is an error object with underlying error. type Error struct { message string inner error } +// Error implements error.Error(). func (v *Error) Error() string { return v.message } +// Inner implements hasInnerError.Inner() func (v *Error) Inner() error { if v.inner == nil { return nil @@ -26,12 +31,14 @@ func (v *Error) Inner() error { return v.inner } +// New returns a new error object with message formed from given arguments. func New(msg ...interface{}) error { return &Error{ message: serial.Concat(msg...), } } +// Base returns an ErrorBuilder based on the given error. func Base(err error) ErrorBuilder { return ErrorBuilder{ error: err, @@ -48,7 +55,7 @@ func Cause(err error) error { return nil } for { - inner, ok := err.(HasInnerError) + inner, ok := err.(hasInnerError) if !ok { break } @@ -64,6 +71,7 @@ type ErrorBuilder struct { error } +// Message returns an error object with given message and base error. func (v ErrorBuilder) Message(msg ...interface{}) error { if v.error == nil { return nil @@ -75,6 +83,7 @@ func (v ErrorBuilder) Message(msg ...interface{}) error { } } +// Format returns an errors object with given message format and base error. func (v ErrorBuilder) Format(format string, values ...interface{}) error { if v.error == nil { return nil diff --git a/common/net/address.proto b/common/net/address.proto index 399fcbf5..4670b769 100644 --- a/common/net/address.proto +++ b/common/net/address.proto @@ -6,6 +6,7 @@ option go_package = "net"; option java_package = "com.v2ray.core.common.net"; option java_multiple_files = true; +// Address of a network host. It may be an IP address or a domain address. message IPOrDomain { oneof address { // IP address. Must by either 4 or 16 bytes. @@ -14,4 +15,4 @@ message IPOrDomain { // Domain address. string domain = 2; } -} \ No newline at end of file +} diff --git a/common/net/destination.go b/common/net/destination.go index 47087a8d..0675ab24 100644 --- a/common/net/destination.go +++ b/common/net/destination.go @@ -18,7 +18,7 @@ func DestinationFromAddr(addr net.Addr) Destination { case *net.UDPAddr: return UDPDestination(IPAddress(addr.IP), Port(addr.Port)) default: - panic("Unknown address type.") + panic("Net: Unknown address type.") } } diff --git a/common/net/destination.proto b/common/net/destination.proto index a19f88c8..c9a0b2af 100644 --- a/common/net/destination.proto +++ b/common/net/destination.proto @@ -9,6 +9,7 @@ option java_multiple_files = true; import "v2ray.com/core/common/net/network.proto"; import "v2ray.com/core/common/net/address.proto"; +// Endpoint of a network connection. message Endpoint { Network network = 1; IPOrDomain address = 2; diff --git a/common/net/network.proto b/common/net/network.proto index ee51bf3d..19a75ad6 100644 --- a/common/net/network.proto +++ b/common/net/network.proto @@ -9,12 +9,8 @@ option java_multiple_files = true; enum Network { Unknown = 0; - // Native TCP provided by system. RawTCP = 1 [deprecated=true]; - - // V2Ray specific TCP. TCP = 2; - UDP = 3; } diff --git a/common/net/port.proto b/common/net/port.proto index ed04f871..fc3fcfdb 100644 --- a/common/net/port.proto +++ b/common/net/port.proto @@ -8,6 +8,8 @@ option java_multiple_files = true; // PortRange represents a range of ports. message PortRange { + // The port that this range starts from. uint32 From = 1; + // The port that this range ends with (inclusive). uint32 To = 2; }