hopp/dial.go
2025-01-09 02:31:15 -05:00

53 lines
1.6 KiB
Go

package hopp
import "context"
import "crypto/tls"
// TODO: dial should be super simple like it is now, and there should be a
// "dialer" which the dial function dial configures automaticaly, but the dialer
// should offer much more options when used directlym
// Dial opens a connection to a server. The network must be one of "udp",
// "udp4", "udp6", or "unixgram".
func Dial(ctx context.Context, network, address string) (Conn, error) {
return (Dialer { }).Dial(ctx, network, address)
}
// TODO: export when there are options here
type Dialer struct {
TLSConfig *tls.Config
}
// Dial opens a connection to a server. The network must be one of "quic",
// "quic4", "quic6", or "unix".
func (diale Dialer) Dial(ctx context.Context, network, address string) (Conn, error) {
switch network {
case "quic", "quic4", "quic6": return diale.dialQUIC(ctx, network, address)
case "unix": return diale.dialUnix(ctx, network, address)
default: return nil, ErrUnknownNetwork
}
}
func (diale Dialer) dialQUIC(ctx context.Context, network, address string) (Conn, error) {
// TODO: dial a QUIC connection and return METADAPT-B wrapping it
}
func (diale Dialer) dialUnix(ctx context.Context, network, address string) (Conn, error) {
if network != "unix" { return nil, ErrUnknownNetwork }
// TODO: dial a unix stream connection and return METADAPT-A wrapping it
}
// addrStrs implements net.Addr
type addrStrs struct {
net string
addr string
}
func (addr addrStrs) Network() string {
return addr.net
}
func (addr addrStrs) String() string {
return addr.addr
}