Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests for packetconn #833

Merged
merged 14 commits into from
Sep 13, 2023
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ kubectl
.vagrant/
/docs/build
/dist
/test-configs
coverage.txt
14 changes: 7 additions & 7 deletions pkg/netceptor/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (s *Netceptor) listen(ctx context.Context, service string, tlscfg *tls.Conf
return nil, fmt.Errorf("service name %s too long", service)
}
if service == "" {
service = s.getEphemeralService()
service = s.GetEphemeralService()
}
s.listenerLock.Lock()
defer s.listenerLock.Unlock()
Expand All @@ -58,7 +58,7 @@ func (s *Netceptor) listen(ctx context.Context, service string, tlscfg *tls.Conf
if isReserved || isListening {
return nil, fmt.Errorf("service %s is already listening", service)
}
_ = s.addNameHash(service)
_ = s.AddNameHash(service)
var connType byte
if tlscfg == nil {
connType = ConnTypeStream
Expand Down Expand Up @@ -86,7 +86,7 @@ func (s *Netceptor) listen(ctx context.Context, service string, tlscfg *tls.Conf
connType: connType,
hopsToLive: s.maxForwardingHops,
}
pc.startUnreachable()
pc.StartUnreachable()
s.Logger.Debug("%s added service %s to listener registry", s.nodeID, service)
s.listenerRegistry[service] = pc
cfg := &quic.Config{
Expand All @@ -98,7 +98,7 @@ func (s *Netceptor) listen(ctx context.Context, service string, tlscfg *tls.Conf
return nil, err
}
if advertise {
s.addLocalServiceAdvertisement(service, connType, adTags)
s.AddLocalServiceAdvertisement(service, connType, adTags)
}
doneChan := make(chan struct{})
go func() {
Expand Down Expand Up @@ -276,8 +276,8 @@ func (s *Netceptor) Dial(node string, service string, tlscfg *tls.Config) (*Conn

// DialContext is like Dial but uses a context to allow timeout or cancellation.
func (s *Netceptor) DialContext(ctx context.Context, node string, service string, tlscfg *tls.Config) (*Conn, error) {
_ = s.addNameHash(node)
_ = s.addNameHash(service)
_ = s.AddNameHash(node)
_ = s.AddNameHash(service)
pc, err := s.ListenPacket("")
if err != nil {
return nil, err
Expand Down Expand Up @@ -425,7 +425,7 @@ func (c *Conn) CloseConnection() error {
c.doneOnce.Do(func() {
close(c.doneChan)
})
c.s.Logger.Debug("closing connection from service %s to %s", c.pc.GetLocalService(), c.RemoteAddr().String())
c.s.Logger.Debug("closing connection from service %s to %s", c.pc.LocalService(), c.RemoteAddr().String())

return c.qc.CloseWithError(0, "normal close")
}
Expand Down
245 changes: 238 additions & 7 deletions pkg/netceptor/mock_netceptor/packetconn.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading