dae/component/outbound/dialer/block.go

51 lines
1.1 KiB
Go
Raw Normal View History

2023-01-27 01:10:27 +07:00
/*
* SPDX-License-Identifier: AGPL-3.0-only
2023-03-14 14:01:55 +07:00
* Copyright (c) 2022-2023, daeuniverse Organization <dae@v2raya.org>
2023-01-27 01:10:27 +07:00
*/
package dialer
import (
"fmt"
2023-01-27 01:10:27 +07:00
"net"
"github.com/mzz2017/softwind/netproxy"
2023-01-27 01:10:27 +07:00
)
type blockDialer struct {
DialCallback func()
}
2023-01-27 01:10:27 +07:00
func (d *blockDialer) Dial(network, addr string) (c netproxy.Conn, err error) {
magicNetwork, err := netproxy.ParseMagicNetwork(network)
if err != nil {
return nil, err
}
switch magicNetwork.Network {
case "tcp":
return d.DialTcp(addr)
case "udp":
return d.DialUdp(addr)
default:
return nil, fmt.Errorf("%w: %v", netproxy.UnsupportedTunnelTypeError, network)
}
}
func (d *blockDialer) DialTcp(addr string) (c netproxy.Conn, err error) {
d.DialCallback()
return nil, net.ErrClosed
}
func (d *blockDialer) DialUdp(addr string) (c netproxy.PacketConn, err error) {
d.DialCallback()
2023-01-27 01:10:27 +07:00
return nil, net.ErrClosed
}
func NewBlockDialer(option *GlobalOption, dialCallback func()) *Dialer {
2023-02-28 20:25:15 +07:00
return NewDialer(&blockDialer{DialCallback: dialCallback}, option, InstanceOption{CheckEnabled: false}, Property{
Name: "block",
Address: "",
Protocol: "",
Link: "",
})
2023-01-27 01:10:27 +07:00
}