Skip to content

Commit

Permalink
all: imp docs
Browse files Browse the repository at this point in the history
  • Loading branch information
schzhn committed Mar 25, 2024
1 parent 81e8b94 commit c9015e7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 8 additions & 4 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ type Runtime struct {
hostsFile []string
}

// NewRuntime constructs a new runtime client.
// NewRuntime constructs a new runtime client. ip must be valid IP address.
//
// TODO(s.chzhen): Validate IP address.
func NewRuntime(ip netip.Addr) (r *Runtime) {
return &Runtime{
ip: ip,
Expand Down Expand Up @@ -195,8 +197,10 @@ func (ri *RuntimeIndex) Client(ip netip.Addr) (rc *Runtime, ok bool) {
return rc, ok
}

// Add saves the runtime client by ip.
func (ri *RuntimeIndex) Add(ip netip.Addr, rc *Runtime) {
// Add saves the runtime client in the index. IP address of a client must be
// unique. See [Client].
func (ri *RuntimeIndex) Add(rc *Runtime) {
ip := rc.Addr()
ri.index[ip] = rc
}

Expand All @@ -205,7 +209,7 @@ func (ri *RuntimeIndex) Size() (n int) {
return len(ri.index)
}

// Range calls cb for each runtime client.
// Range calls cb for each runtime client in an undefined order.
func (ri *RuntimeIndex) Range(cb func(rc *Runtime) (cont bool)) {
for _, rc := range ri.index {
if !cb(rc) {
Expand Down
6 changes: 3 additions & 3 deletions internal/home/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,8 +736,8 @@ func (clients *clientsContainer) setWHOISInfo(ip netip.Addr, wi *whois.Info) {
if !ok {
// Create a RuntimeClient implicitly so that we don't do this check
// again.
rc = &client.Runtime{}
clients.runtimeIndex.Add(ip, rc)
rc = client.NewRuntime(ip)
clients.runtimeIndex.Add(rc)

log.Debug("clients: set whois info for runtime client with ip %s: %+v", ip, wi)
} else {
Expand Down Expand Up @@ -805,7 +805,7 @@ func (clients *clientsContainer) addHostLocked(
}

rc = client.NewRuntime(ip)
clients.runtimeIndex.Add(ip, rc)
clients.runtimeIndex.Add(rc)
}

rc.SetInfo(src, []string{host})
Expand Down

0 comments on commit c9015e7

Please sign in to comment.