mirror of
https://github.com/fumiama/WireGold.git
synced 2026-06-28 14:50:26 +08:00
feat(p2p): add udplite protocol
This commit is contained in:
27
gold/p2p/udplite/init.go
Normal file
27
gold/p2p/udplite/init.go
Normal file
@@ -0,0 +1,27 @@
|
||||
//go:build !darwin
|
||||
|
||||
package udplite
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/netip"
|
||||
|
||||
"github.com/fumiama/WireGold/gold/p2p"
|
||||
"github.com/fumiama/WireGold/helper"
|
||||
)
|
||||
|
||||
func NewEndpoint(endpoint string, _ ...any) (p2p.EndPoint, error) {
|
||||
addr, err := netip.ParseAddrPort(endpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return (*EndPoint)(net.UDPAddrFromAddrPort(addr)), nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
name := helper.FolderName()
|
||||
_, hasexist := p2p.Register(name, NewEndpoint)
|
||||
if hasexist {
|
||||
panic("network " + name + " has been registered")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user