tun2: Connection is an Fer now

This commit is contained in:
Cadey Ratio 2017-03-26 15:26:59 -07:00
parent 919e160273
commit 3d516cdf4e
1 changed files with 16 additions and 16 deletions

View File

@ -56,6 +56,17 @@ type Connection struct {
cancel context.CancelFunc cancel context.CancelFunc
} }
func (c *Connection) Fer() ln.F {
return map[string]interface{}{
"id": c.id,
"remote": c.conn.RemoteAddr(),
"local": c.conn.LocalAddr(),
"isKCP": c.isKCP,
"user": c.user,
"domain": c.domain,
}
}
func NewServer(cfg *ServerConfig) (*Server, error) { func NewServer(cfg *ServerConfig) (*Server, error) {
if cfg == nil { if cfg == nil {
return nil, errors.New("tun2: config must be specified") return nil, errors.New("tun2: config must be specified")
@ -274,12 +285,7 @@ func (s *Server) HandleConn(c net.Conn, isKCP bool) {
ln.Log(ln.F{ ln.Log(ln.F{
"action": "backend_connected", "action": "backend_connected",
"remote": c.RemoteAddr().String(), }, connection)
"kcp": isKCP,
"domain": auth.Domain,
"user": connection.user,
"id": connection.id,
})
s.connlock.Lock() s.connlock.Lock()
s.conns[c] = connection s.conns[c] = connection
@ -308,10 +314,7 @@ func (s *Server) HandleConn(c net.Conn, isKCP bool) {
ln.Log(ln.F{ ln.Log(ln.F{
"action": "client_disconnecting", "action": "client_disconnecting",
"remote": c.RemoteAddr(), }, connection)
"domain": auth.Domain,
"id": connection.id,
})
controlStream.Close() controlStream.Close()
session.Close() session.Close()
@ -335,11 +338,10 @@ func (s *Server) RoundTrip(req *http.Request) (*http.Response, error) {
if err != nil { if err != nil {
ln.Error(err, ln.F{ ln.Error(err, ln.F{
"action": "opening_session_stream", "action": "opening_session_stream",
"backend": c.conn.RemoteAddr().String(),
"remote_addr": req.RemoteAddr, "remote_addr": req.RemoteAddr,
"host": req.Host, "host": req.Host,
"uri": req.RequestURI, "uri": req.RequestURI,
}) }, c)
c.cancel() c.cancel()
@ -351,11 +353,10 @@ func (s *Server) RoundTrip(req *http.Request) (*http.Response, error) {
if err != nil { if err != nil {
ln.Error(err, ln.F{ ln.Error(err, ln.F{
"action": "request_writing", "action": "request_writing",
"backend": c.conn.RemoteAddr().String(),
"remote_addr": req.RemoteAddr, "remote_addr": req.RemoteAddr,
"host": req.Host, "host": req.Host,
"uri": req.RequestURI, "uri": req.RequestURI,
}) }, c)
c.cancel() c.cancel()
@ -368,11 +369,10 @@ func (s *Server) RoundTrip(req *http.Request) (*http.Response, error) {
if err != nil { if err != nil {
ln.Error(err, ln.F{ ln.Error(err, ln.F{
"action": "response_reading", "action": "response_reading",
"backend": c.conn.RemoteAddr().String(),
"remote_addr": req.RemoteAddr, "remote_addr": req.RemoteAddr,
"host": req.Host, "host": req.Host,
"uri": req.RequestURI, "uri": req.RequestURI,
}) }, c)
c.cancel() c.cancel()