2019-12-08 12:17:24 +08:00
|
|
|
package outbound
|
2018-06-10 22:50:03 +08:00
|
|
|
|
|
|
|
import (
|
2019-10-12 23:55:39 +08:00
|
|
|
"context"
|
2019-12-30 10:51:35 +08:00
|
|
|
"errors"
|
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
|
|
|
|
2021-11-07 16:48:51 +08:00
|
|
|
"github.com/Dreamacro/clash/component/dialer"
|
2018-06-10 22:50:03 +08:00
|
|
|
C "github.com/Dreamacro/clash/constant"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Reject struct {
|
2018-12-22 23:56:42 +08:00
|
|
|
*Base
|
2018-06-10 22:50:03 +08:00
|
|
|
}
|
|
|
|
|
2021-04-29 11:23:14 +08:00
|
|
|
// DialContext implements C.ProxyAdapter
|
2021-11-07 16:48:51 +08:00
|
|
|
func (r *Reject) DialContext(ctx context.Context, metadata *C.Metadata, opts ...dialer.Option) (C.Conn, error) {
|
2020-03-21 23:46:49 +08:00
|
|
|
return NewConn(&NopConn{}, r), nil
|
2018-11-21 13:47:46 +08:00
|
|
|
}
|
|
|
|
|
2021-10-15 21:44:53 +08:00
|
|
|
// ListenPacketContext implements C.ProxyAdapter
|
2021-11-07 16:48:51 +08:00
|
|
|
func (r *Reject) ListenPacketContext(ctx context.Context, metadata *C.Metadata, opts ...dialer.Option) (C.PacketConn, error) {
|
2020-01-31 14:43:54 +08:00
|
|
|
return nil, errors.New("match reject rule")
|
2019-12-30 10:51:35 +08:00
|
|
|
}
|
|
|
|
|
2018-06-10 22:50:03 +08:00
|
|
|
func NewReject() *Reject {
|
2018-12-22 23:56:42 +08:00
|
|
|
return &Reject{
|
|
|
|
Base: &Base{
|
|
|
|
name: "REJECT",
|
|
|
|
tp: C.Reject,
|
2019-12-30 10:51:35 +08:00
|
|
|
udp: true,
|
2018-12-22 23:56:42 +08:00
|
|
|
},
|
|
|
|
}
|
2018-06-10 22:50:03 +08:00
|
|
|
}
|
|
|
|
|
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-11-25 17:00:11 +08:00
|
|
|
return 0, io.EOF
|
2018-06-10 22:50:03 +08:00
|
|
|
}
|
|
|
|
|
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 }
|