2019-12-08 04:17:24 +00:00
|
|
|
package outbound
|
2018-06-10 14:50:03 +00:00
|
|
|
|
|
|
|
import (
|
2019-10-12 15:55:39 +00:00
|
|
|
"context"
|
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
|
|
|
|
2021-11-07 08:48:51 +00:00
|
|
|
"github.com/Dreamacro/clash/component/dialer"
|
2018-06-10 14:50:03 +00:00
|
|
|
C "github.com/Dreamacro/clash/constant"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Reject struct {
|
2018-12-22 15:56:42 +00:00
|
|
|
*Base
|
2018-06-10 14:50:03 +00:00
|
|
|
}
|
|
|
|
|
2021-04-29 03:23:14 +00:00
|
|
|
// DialContext implements C.ProxyAdapter
|
2021-11-07 08:48:51 +00:00
|
|
|
func (r *Reject) DialContext(ctx context.Context, metadata *C.Metadata, opts ...dialer.Option) (C.Conn, error) {
|
2021-11-20 04:34:14 +00:00
|
|
|
return NewConn(&nopConn{}, r), nil
|
2018-11-21 05:47:46 +00:00
|
|
|
}
|
|
|
|
|
2021-10-15 13:44:53 +00:00
|
|
|
// ListenPacketContext implements C.ProxyAdapter
|
2021-11-07 08:48:51 +00:00
|
|
|
func (r *Reject) ListenPacketContext(ctx context.Context, metadata *C.Metadata, opts ...dialer.Option) (C.PacketConn, error) {
|
2021-11-20 04:44:31 +00:00
|
|
|
return newPacketConn(&nopPacketConn{}, r), nil
|
2019-12-30 02:51:35 +00:00
|
|
|
}
|
|
|
|
|
2018-06-10 14:50:03 +00:00
|
|
|
func NewReject() *Reject {
|
2018-12-22 15:56:42 +00:00
|
|
|
return &Reject{
|
|
|
|
Base: &Base{
|
2022-08-28 05:41:19 +00:00
|
|
|
name: "REJECT",
|
|
|
|
tp: C.Reject,
|
|
|
|
udp: true,
|
|
|
|
prefer: C.DualStack,
|
2018-12-22 15:56:42 +00:00
|
|
|
},
|
|
|
|
}
|
2018-06-10 14:50:03 +00:00
|
|
|
}
|
|
|
|
|
2022-05-02 01:16:47 +00:00
|
|
|
func NewPass() *Reject {
|
|
|
|
return &Reject{
|
|
|
|
Base: &Base{
|
2022-08-28 05:41:19 +00:00
|
|
|
name: "PASS",
|
|
|
|
tp: C.Pass,
|
|
|
|
udp: true,
|
|
|
|
prefer: C.DualStack,
|
2022-05-02 01:16:47 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-20 04:34:14 +00:00
|
|
|
type nopConn struct{}
|
2018-06-10 14:50:03 +00:00
|
|
|
|
2021-11-20 04:34:14 +00:00
|
|
|
func (rw *nopConn) Read(b []byte) (int, error) {
|
2018-11-25 09:00:11 +00:00
|
|
|
return 0, io.EOF
|
2018-06-10 14:50:03 +00:00
|
|
|
}
|
|
|
|
|
2021-11-20 04:34:14 +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
|
|
|
|
2021-11-20 04:34:14 +00:00
|
|
|
func (rw *nopConn) Close() error { return nil }
|
|
|
|
func (rw *nopConn) LocalAddr() net.Addr { return nil }
|
|
|
|
func (rw *nopConn) RemoteAddr() net.Addr { return nil }
|
|
|
|
func (rw *nopConn) SetDeadline(time.Time) error { return nil }
|
|
|
|
func (rw *nopConn) SetReadDeadline(time.Time) error { return nil }
|
|
|
|
func (rw *nopConn) SetWriteDeadline(time.Time) error { return nil }
|
2018-07-31 09:53:39 +00:00
|
|
|
|
2021-11-20 04:44:31 +00:00
|
|
|
type nopPacketConn struct{}
|
2018-07-31 09:53:39 +00:00
|
|
|
|
2021-11-20 04:44:31 +00:00
|
|
|
func (npc *nopPacketConn) WriteTo(b []byte, addr net.Addr) (n int, err error) { return len(b), nil }
|
|
|
|
func (npc *nopPacketConn) ReadFrom(b []byte) (int, net.Addr, error) { return 0, nil, io.EOF }
|
|
|
|
func (npc *nopPacketConn) Close() error { return nil }
|
|
|
|
func (npc *nopPacketConn) LocalAddr() net.Addr { return &net.UDPAddr{IP: net.IPv4zero, Port: 0} }
|
|
|
|
func (npc *nopPacketConn) SetDeadline(time.Time) error { return nil }
|
|
|
|
func (npc *nopPacketConn) SetReadDeadline(time.Time) error { return nil }
|
|
|
|
func (npc *nopPacketConn) SetWriteDeadline(time.Time) error { return nil }
|