clash/adapters/outbound/reject.go

62 lines
1.3 KiB
Go
Raw Normal View History

2019-12-08 12:17:24 +08:00
package outbound
2018-06-10 22:50:03 +08:00
import (
"context"
"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
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
}
func (r *Reject) DialContext(ctx context.Context, metadata *C.Metadata) (C.Conn, error) {
return newConn(&NopConn{}, r), nil
2018-11-21 13:47:46 +08:00
}
func (r *Reject) DialUDP(metadata *C.Metadata) (C.PacketConn, net.Addr, error) {
return nil, nil, errors.New("match reject rule")
}
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,
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) {
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 }