mihomo/adapters/outbound/reject.go

77 lines
1.6 KiB
Go
Raw Normal View History

2018-06-10 22:50:03 +08:00
package adapters
import (
2018-11-21 13:47:46 +08:00
"encoding/json"
2018-06-10 22:50:03 +08:00
"io"
2018-06-14 01:00:58 +08:00
"net"
2018-07-31 17:53:39 +08:00
"time"
2018-06-10 22:50:03 +08:00
C "github.com/Dreamacro/clash/constant"
)
// RejectAdapter is a reject connected adapter
type RejectAdapter struct {
2018-07-31 17:53:39 +08:00
conn net.Conn
2018-06-10 22:50:03 +08:00
}
2018-06-14 01:00:58 +08:00
// Close is used to close connection
func (r *RejectAdapter) Close() {}
2018-06-10 22:50:03 +08:00
2018-06-17 22:41:32 +08:00
// Conn is used to http request
2018-06-14 01:00:58 +08:00
func (r *RejectAdapter) Conn() net.Conn {
2018-07-31 17:53:39 +08:00
return r.conn
2018-06-10 22:50:03 +08:00
}
type Reject struct {
}
2018-06-16 21:34:13 +08:00
func (r *Reject) Name() string {
2018-10-19 20:28:19 +08:00
return "REJECT"
2018-06-16 21:34:13 +08:00
}
func (r *Reject) Type() C.AdapterType {
return C.Reject
}
2018-09-30 12:25:52 +08:00
func (r *Reject) Generator(metadata *C.Metadata) (adapter C.ProxyAdapter, err error) {
2018-07-31 17:53:39 +08:00
return &RejectAdapter{conn: &NopConn{}}, nil
2018-06-10 22:50:03 +08:00
}
2018-11-21 13:47:46 +08:00
func (r *Reject) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]string{
"type": r.Type().String(),
})
}
2018-06-10 22:50:03 +08:00
func NewReject() *Reject {
return &Reject{}
}
2018-07-31 17:53:39 +08:00
type NopConn struct{}
2018-06-10 22:50:03 +08:00
2018-07-31 17:53:39 +08:00
func (rw *NopConn) Read(b []byte) (int, error) {
2018-06-10 22:50:03 +08:00
return len(b), nil
}
2018-07-31 17:53:39 +08:00
func (rw *NopConn) Write(b []byte) (int, error) {
2018-06-10 22:50:03 +08:00
return 0, io.EOF
}
2018-07-31 17:53:39 +08:00
// Close is fake function for net.Conn
func (rw *NopConn) Close() error { return nil }
// LocalAddr is fake function for net.Conn
func (rw *NopConn) LocalAddr() net.Addr { return nil }
// RemoteAddr is fake function for net.Conn
func (rw *NopConn) RemoteAddr() net.Addr { return nil }
// SetDeadline is fake function for net.Conn
func (rw *NopConn) SetDeadline(time.Time) error { return nil }
// SetReadDeadline is fake function for net.Conn
func (rw *NopConn) SetReadDeadline(time.Time) error { return nil }
// SetWriteDeadline is fake function for net.Conn
func (rw *NopConn) SetWriteDeadline(time.Time) error { return nil }