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