2016-03-14 03:18:24 +00:00
|
|
|
// Copyright 2016 fatedier, fatedier@gmail.com
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2017-03-08 18:03:47 +00:00
|
|
|
package net
|
2016-02-18 08:56:55 +00:00
|
|
|
|
2017-03-08 18:03:47 +00:00
|
|
|
import (
|
2017-05-26 06:17:46 +00:00
|
|
|
"io"
|
2017-03-08 18:03:47 +00:00
|
|
|
"net"
|
2017-05-26 06:17:46 +00:00
|
|
|
"time"
|
2016-02-18 08:56:55 +00:00
|
|
|
|
2017-03-08 18:03:47 +00:00
|
|
|
"github.com/fatedier/frp/utils/log"
|
2016-07-17 13:42:21 +00:00
|
|
|
)
|
|
|
|
|
2017-03-08 18:03:47 +00:00
|
|
|
// Conn is the interface of connections used in frp.
|
|
|
|
type Conn interface {
|
|
|
|
net.Conn
|
|
|
|
log.Logger
|
|
|
|
}
|
|
|
|
|
2017-05-17 09:47:20 +00:00
|
|
|
type WrapLogConn struct {
|
|
|
|
net.Conn
|
|
|
|
log.Logger
|
|
|
|
}
|
|
|
|
|
|
|
|
func WrapConn(c net.Conn) Conn {
|
2017-05-26 06:17:46 +00:00
|
|
|
return &WrapLogConn{
|
2017-05-17 09:47:20 +00:00
|
|
|
Conn: c,
|
|
|
|
Logger: log.NewPrefixLogger(""),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-26 06:17:46 +00:00
|
|
|
type WrapReadWriteCloserConn struct {
|
|
|
|
io.ReadWriteCloser
|
|
|
|
log.Logger
|
|
|
|
}
|
|
|
|
|
|
|
|
func (conn *WrapReadWriteCloserConn) LocalAddr() net.Addr {
|
2017-05-30 06:37:51 +00:00
|
|
|
return (*net.TCPAddr)(nil)
|
2017-05-26 06:17:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (conn *WrapReadWriteCloserConn) RemoteAddr() net.Addr {
|
2017-05-30 06:37:51 +00:00
|
|
|
return (*net.TCPAddr)(nil)
|
2017-05-26 06:17:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (conn *WrapReadWriteCloserConn) SetDeadline(t time.Time) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (conn *WrapReadWriteCloserConn) SetReadDeadline(t time.Time) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (conn *WrapReadWriteCloserConn) SetWriteDeadline(t time.Time) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func WrapReadWriteCloserToConn(rwc io.ReadWriteCloser) Conn {
|
|
|
|
return &WrapReadWriteCloserConn{
|
|
|
|
ReadWriteCloser: rwc,
|
|
|
|
Logger: log.NewPrefixLogger(""),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-08 18:03:47 +00:00
|
|
|
type Listener interface {
|
|
|
|
Accept() (Conn, error)
|
|
|
|
Close() error
|
2017-03-11 18:03:24 +00:00
|
|
|
log.Logger
|
2017-03-08 18:03:47 +00:00
|
|
|
}
|