Skip to content

Commit

Permalink
refactor(api): Make maxConcurrentCaptures uint32 to avoid cast.
Browse files Browse the repository at this point in the history
  • Loading branch information
domdom82 committed Aug 7, 2023
1 parent ead83a2 commit 13b7e2a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/pcap/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ type API struct {
// id of the instance where the api is located.
id string

maxConcurrentCaptures uint
concurrentStreams atomic.Int32
maxConcurrentCaptures uint32
concurrentStreams atomic.Uint32
tlsCredentials credentials.TransportCredentials

UnimplementedAPIServer
}

func NewAPI(bufConf BufferConf, clientTLS *ClientTLS, id string, maxConcurrentCaptures uint) (*API, error) {
func NewAPI(bufConf BufferConf, clientTLS *ClientTLS, id string, maxConcurrentCaptures uint32) (*API, error) {
clientTLSCreds := insecure.NewCredentials()
if clientTLS != nil {
clientTLSConf, err := clientTLS.Config()
Expand Down Expand Up @@ -180,9 +180,9 @@ func (api *API) Capture(stream API_CaptureServer) (err error) {

currentStreams := api.concurrentStreams.Add(1)

defer api.concurrentStreams.Add(-1)
defer api.concurrentStreams.Add(^uint32(0)) // subtract 1 by adding binary complement of 0

if currentStreams > int32(api.maxConcurrentCaptures) {
if currentStreams > api.maxConcurrentCaptures {
vcapID, ok := ctx.Value(HeaderVcapID).(string)
if !ok {
return errorf(codes.ResourceExhausted, "failed starting capture: %w", errTooManyCaptures)
Expand Down
2 changes: 1 addition & 1 deletion src/pcap/cmd/pcap-api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var DefaultAPIConfig = APIConfig{
type APIConfig struct {
pcap.NodeConfig `yaml:"-,inline"`
AgentsMTLS *pcap.ClientTLS `yaml:"agents_mtls" validate:"omitempty"`
ConcurrentCaptures uint `yaml:"concurrent_captures"`
ConcurrentCaptures uint32 `yaml:"concurrent_captures"`
DrainTimeout time.Duration `yaml:"drain_timeout"`

BoshResolverConfig *pcap.BoshResolverConfig `yaml:"bosh,omitempty" validate:"dive"`
Expand Down
2 changes: 1 addition & 1 deletion src/pcap/test/integration/agent_api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

var apiClient pcap.APIClient

var MaxConcurrentCaptures uint = 2
var MaxConcurrentCaptures uint32 = 2

// port is used for creating agents.
var port = 9494
Expand Down

0 comments on commit 13b7e2a

Please sign in to comment.