package ice
import (
"net/netip"
"strings"
)
type CandidateHost struct {
candidateBase
network string
}
type CandidateHostConfig struct {
CandidateID string
Network string
Address string
Port int
Component uint16
Priority uint32
Foundation string
TCPType TCPType
IsLocationTracked bool
}
func NewCandidateHost (config *CandidateHostConfig ) (*CandidateHost , error ) {
candidateID := config .CandidateID
if candidateID == "" {
candidateID = globalCandidateIDGenerator .Generate ()
}
candidateHost := &CandidateHost {
candidateBase : candidateBase {
id : candidateID ,
address : config .Address ,
candidateType : CandidateTypeHost ,
component : config .Component ,
port : config .Port ,
tcpType : config .TCPType ,
foundationOverride : config .Foundation ,
priorityOverride : config .Priority ,
remoteCandidateCaches : map [AddrPort ]Candidate {},
isLocationTracked : config .IsLocationTracked ,
},
network : config .Network ,
}
if !strings .HasSuffix (config .Address , ".local" ) {
ipAddr , err := netip .ParseAddr (config .Address )
if err != nil {
return nil , err
}
if err := candidateHost .setIPAddr (ipAddr ); err != nil {
return nil , err
}
} else {
candidateHost .candidateBase .networkType = NetworkTypeUDP4
}
return candidateHost , nil
}
func (c *CandidateHost ) setIPAddr (addr netip .Addr ) error {
networkType , err := determineNetworkType (c .network , addr )
if err != nil {
return err
}
c .candidateBase .networkType = networkType
c .candidateBase .resolvedAddr = createAddr (networkType , addr , c .port )
return nil
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .