refactor log and error

This commit is contained in:
Darien Raymond committed 2017-04-06 21:13:17 +02:00
1 parent fc31f9b94c
commit 75f5cb9afb
33 files changed
+123 -99

No files matched your search

+5 -5
View File
@@ -203,7 +203,7 @@ type Connection struct {
// NewConnection create a new KCP connection between local and remote.
func NewConnection(conv uint16, sysConn SystemConnection, recycler internal.ConnectionRecyler, config *Config) *Connection {
log.Info("KCP|Connection: creating connection ", conv)
log.Trace(errors.New("KCP|Connection: creating connection ", conv))
conn := &Connection{
conv: conv,
@@ -341,7 +341,7 @@ func (v *Connection) SetState(state State) {
current := v.Elapsed()
atomic.StoreInt32((*int32)(&v.state), int32(state))
atomic.StoreUint32(&v.stateBeginTime, current)
log.Debug("KCP|Connection: #", v.conv, " entering state ", state, " at ", current)
log.Trace(errors.New("KCP|Connection: #", v.conv, " entering state ", state, " at ", current).AtDebug())
switch state {
case StateReadyToClose:
@@ -378,7 +378,7 @@ func (v *Connection) Close() error {
if state.Is(StateReadyToClose, StateTerminating, StateTerminated) {
return ErrClosedConnection
}
log.Info("KCP|Connection: Closing connection to ", v.conn.RemoteAddr())
log.Trace(errors.New("KCP|Connection: Closing connection to ", v.conn.RemoteAddr()))
if state == StateActive {
v.SetState(StateReadyToClose)
@@ -455,7 +455,7 @@ func (v *Connection) Terminate() {
if v == nil {
return
}
log.Info("KCP|Connection: Terminating connection to ", v.RemoteAddr())
log.Trace(errors.New("KCP|Connection: Terminating connection to ", v.RemoteAddr()))
//v.SetState(StateTerminated)
v.OnDataInput()
@@ -549,7 +549,7 @@ func (v *Connection) flush() {
}
if v.State() == StateTerminating {
log.Debug("KCP|Connection: #", v.conv, " sending terminating cmd.")
log.Trace(errors.New("KCP|Connection: #", v.conv, " sending terminating cmd.").AtDebug())
v.Ping(current, CommandTerminate)
if current-atomic.LoadUint32(&v.stateBeginTime) > 8000 {
+2 -2
View File
@@ -111,7 +111,7 @@ func (o *ClientConnection) Run() {
func DialKCP(ctx context.Context, dest v2net.Destination) (internet.Connection, error) {
dest.Network = v2net.Network_UDP
log.Info("KCP|Dialer: Dialing KCP to ", dest)
log.Trace(errors.New("KCP|Dialer: Dialing KCP to ", dest))
src := internet.DialerSourceFromContext(ctx)
id := internal.NewConnectionID(src, dest)
@@ -119,7 +119,7 @@ func DialKCP(ctx context.Context, dest v2net.Destination) (internet.Connection,
if conn == nil {
rawConn, err := internet.DialSystem(ctx, src, dest)
if err != nil {
log.Error("KCP|Dialer: Failed to dial to dest: ", err)
log.Trace(errors.New("KCP|Dialer: Failed to dial to dest: ", err).AtError())
return nil, err
}
c := &ClientConnection{
+2 -2
View File
@@ -130,7 +130,7 @@ func NewListener(ctx context.Context, address v2net.Address, port v2net.Port, co
l.Lock()
l.hub = hub
l.Unlock()
log.Info("KCP|Listener: listening on ", address, ":", port)
log.Trace(errors.New("KCP|Listener: listening on ", address, ":", port))
return l, nil
}
@@ -139,7 +139,7 @@ func (v *Listener) OnReceive(payload *buf.Buffer, src v2net.Destination, origina
segments := v.reader.Read(payload.Bytes())
if len(segments) == 0 {
log.Info("KCP|Listener: discarding invalid payload from ", src)
log.Trace(errors.New("KCP|Listener: discarding invalid payload from ", src))
return
}
+1 -1
View File
@@ -19,7 +19,7 @@ var (
)
func Dial(ctx context.Context, dest v2net.Destination) (internet.Connection, error) {
log.Info("Internet|TCP: Dailing TCP to ", dest)
log.Trace(errors.New("Internet|TCP: Dailing TCP to ", dest))
src := internet.DialerSourceFromContext(ctx)
tcpSettings := internet.TransportSettingsFromContext(ctx).(*Config)
+2 -2
View File
@@ -37,7 +37,7 @@ func ListenTCP(ctx context.Context, address v2net.Address, port v2net.Port, conn
if err != nil {
return nil, err
}
log.Info("TCP|Listener: Listening on ", address, ":", port)
log.Trace(errors.New("TCP|Listener: Listening on ", address, ":", port))
networkSettings := internet.TransportSettingsFromContext(ctx)
tcpSettings := networkSettings.(*Config)
@@ -85,7 +85,7 @@ func (v *TCPListener) KeepAccepting() {
return nil
})
if err != nil {
log.Warning("TCP|Listener: Failed to accepted raw connections: ", err)
log.Trace(errors.New("TCP|Listener: Failed to accepted raw connections: ", err).AtWarning())
continue
}
+3 -3
View File
@@ -15,18 +15,18 @@ const SO_ORIGINAL_DST = 80
func GetOriginalDestination(conn internet.Connection) net.Destination {
tcpConn, ok := conn.(internet.SysFd)
if !ok {
log.Info("Dokodemo: Failed to get sys fd.")
log.Trace(errors.New("Dokodemo: Failed to get sys fd."))
return net.Destination{}
}
fd, err := tcpConn.SysFd()
if err != nil {
log.Info("Dokodemo: Failed to get original destination: ", err)
log.Trace(errors.New("Dokodemo: Failed to get original destination: ", err))
return net.Destination{}
}
addr, err := syscall.GetsockoptIPv6Mreq(fd, syscall.IPPROTO_IP, SO_ORIGINAL_DST)
if err != nil {
log.Info("Dokodemo: Failed to call getsockopt: ", err)
log.Trace(errors.New("Dokodemo: Failed to call getsockopt: ", err))
return net.Destination{}
}
ip := net.IPAddress(addr.Multiaddr[4:8])
+2 -1
View File
@@ -4,6 +4,7 @@ import (
"crypto/tls"
"v2ray.com/core/app/log"
"v2ray.com/core/common/errors"
)
var (
@@ -15,7 +16,7 @@ func (v *Config) BuildCertificates() []tls.Certificate {
for _, entry := range v.Certificate {
keyPair, err := tls.X509KeyPair(entry.Certificate, entry.Key)
if err != nil {
log.Warning("TLS: ignoring invalid X509 key pair: ", err)
log.Trace(errors.New("TLS: ignoring invalid X509 key pair").Base(err).AtWarning())
continue
}
certs = append(certs, keyPair)
+3 -2
View File
@@ -7,6 +7,7 @@ import (
"v2ray.com/core/app/dispatcher"
"v2ray.com/core/app/log"
"v2ray.com/core/common/buf"
"v2ray.com/core/common/errors"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/transport/ray"
)
@@ -44,7 +45,7 @@ func (v *Dispatcher) getInboundRay(ctx context.Context, dest v2net.Destination)
return entry, true
}
log.Info("UDP|Server: establishing new connection for ", dest)
log.Trace(errors.New("UDP|Server: establishing new connection for ", dest))
inboundRay, _ := v.dispatcher.Dispatch(ctx, dest)
v.conns[dest] = inboundRay
return inboundRay, false
@@ -52,7 +53,7 @@ func (v *Dispatcher) getInboundRay(ctx context.Context, dest v2net.Destination)
func (v *Dispatcher) Dispatch(ctx context.Context, destination v2net.Destination, payload *buf.Buffer, callback ResponseCallback) {
// TODO: Add user to destString
log.Debug("UDP|Server: Dispatch request: ", destination)
log.Trace(errors.New("UDP|Server: Dispatch request: ", destination).AtDebug())
inboundRay, existing := v.getInboundRay(ctx, destination)
outputStream := inboundRay.InboundInput()
+2 -2
View File
@@ -93,7 +93,7 @@ func ListenUDP(address v2net.Address, port v2net.Port, option ListenOption) (*Hu
if err != nil {
return nil, err
}
log.Info("UDP|Hub: Listening on ", address, ":", port)
log.Trace(errors.New("UDP|Hub: Listening on ", address, ":", port))
if option.ReceiveOriginalDest {
fd, err := internal.GetSysFd(udpConn)
if err != nil {
@@ -148,7 +148,7 @@ L:
})
if err != nil {
log.Info("UDP|Hub: Failed to read UDP msg: ", err)
log.Trace(errors.New("UDP|Hub: Failed to read UDP msg: ", err))
buffer.Release()
continue
}
+1 -1
View File
@@ -19,7 +19,7 @@ var (
)
func Dial(ctx context.Context, dest v2net.Destination) (internet.Connection, error) {
log.Info("WebSocket|Dialer: Creating connection to ", dest)
log.Trace(errors.New("WebSocket|Dialer: Creating connection to ", dest))
src := internet.DialerSourceFromContext(ctx)
wsSettings := internet.TransportSettingsFromContext(ctx).(*Config)
+1 -1
View File
@@ -35,7 +35,7 @@ func (h *requestHandler) ServeHTTP(writer http.ResponseWriter, request *http.Req
}
conn, err := converttovws(writer, request)
if err != nil {
log.Info("WebSocket|Listener: Failed to convert to WebSocket connection: ", err)
log.Trace(errors.New("WebSocket|Listener: Failed to convert to WebSocket connection: ", err))
return
}