Skip to content

Commit

Permalink
Add unit tests for packetconn (#833)
Browse files Browse the repository at this point in the history
  • Loading branch information
matoval authored Sep 13, 2023
1 parent a050b6c commit 9b707e6
Show file tree
Hide file tree
Showing 7 changed files with 630 additions and 59 deletions.
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

0 comments on commit 9b707e6

Please sign in to comment.