netbounce/config/udp.go
2025-04-21 07:11:02 +10:00

83 lines
1.8 KiB
Go

package config
/*
Copyright 2025 Suyono <suyono3484@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import (
"fmt"
"net"
"time"
"gitea.suyono.dev/suyono/netbounce/abstract"
)
type udpConfig struct {
Name string `mapstructure:"-,"`
Type abstract.ConnectionType `mapstructure:"-,"`
Listen string `mapstructure:"listen"`
Backend string `mapstructure:"backend"`
Timeout time.Duration `mapstructure:"timeout,30m"`
}
type udpBackendAddr struct {
config udpConfig
}
type udpModule struct {
config udpConfig
}
func (u udpModule) AsUDP() abstract.UDPConnectionConfig {
return u
}
func (u udpModule) AsTCP() abstract.TCPConnectionConfig {
panic(fmt.Errorf("not UDP"))
// return nil
}
func (u udpModule) Name() string {
return u.config.Name
}
func (u udpModule) Type() abstract.ConnectionType {
return u.config.Type
}
func (u udpModule) Listen() string {
return u.config.Listen
}
func (u udpModule) Backend() string {
return u.config.Backend
}
func (u udpModule) Timeout() time.Duration {
return u.config.Timeout
}
func (u udpModule) BackendAddr() net.Addr {
return udpBackendAddr(u)
}
func (a udpBackendAddr) Network() string {
return "udp"
}
func (a udpBackendAddr) String() string {
return a.config.Backend
}