Skip to content

Commit

Permalink
Make specific version selector functions public - needed by the gen-b…
Browse files Browse the repository at this point in the history
…ias tool in the client repo
  • Loading branch information
ewust committed Apr 3, 2024
1 parent 6e9ba3c commit 98adf4f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions pkg/phantoms/compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ func (sc *SubnetConfig) getSubnetsVarint(seed []byte, weighted bool) ([]*phantom
return out, nil
}

// selectPhantomImplVarint - select an ip address from the list of subnets
// SelectPhantomImplVarint - select an ip address from the list of subnets
// associated with the specified generation by constructing a set of start and
// end values for the high and low values in each allocation. The random number
// is then bound between the global min and max of that set. This ensures that
// addresses are chosen based on the number of addresses in the subnet.
func selectPhantomImplVarint(seed []byte, subnets []*phantomNet) (*PhantomIP, error) {
func SelectPhantomImplVarint(seed []byte, subnets []*phantomNet) (*PhantomIP, error) {
type idNet struct {
min, max big.Int
net *phantomNet
Expand Down Expand Up @@ -129,9 +129,9 @@ func selectPhantomImplVarint(seed []byte, subnets []*phantomNet) (*PhantomIP, er
return result, nil
}

// selectPhantomImplV0 implements support for the legacy (buggy) client phantom
// SelectPhantomImplV0 implements support for the legacy (buggy) client phantom
// address selection algorithm.
func selectPhantomImplV0(seed []byte, subnets []*phantomNet) (*PhantomIP, error) {
func SelectPhantomImplV0(seed []byte, subnets []*phantomNet) (*PhantomIP, error) {

addressTotal := big.NewInt(0)

Expand Down
2 changes: 1 addition & 1 deletion pkg/phantoms/phantom_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func getSubnetsHkdf(sc genericSubnetConfig, seed []byte, weighted bool) ([]*phan
return out, nil
}

func selectPhantomImplHkdf(seed []byte, subnets []*phantomNet) (*PhantomIP, error) {
func SelectPhantomImplHkdf(seed []byte, subnets []*phantomNet) (*PhantomIP, error) {
type idNet struct {
min, max big.Int
net *phantomNet
Expand Down
6 changes: 3 additions & 3 deletions pkg/phantoms/station_phantoms.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,22 @@ func (p *PhantomIPSelector) Select(seed []byte, generation uint, clientLibVer ui
// handle legacy clientLibVersions for selecting phantoms.
if clientLibVer < core.PhantomSelectionMinGeneration {
// Version 0
ip, err := selectPhantomImplV0(seed, genSubnets)
ip, err := SelectPhantomImplV0(seed, genSubnets)
if err != nil {
return nil, err
}
return ip, nil
} else if clientLibVer < core.PhantomHkdfMinVersion {
// Version 1
ip, err := selectPhantomImplVarint(seed, genSubnets)
ip, err := SelectPhantomImplVarint(seed, genSubnets)
if err != nil {
return nil, err
}
return ip, nil
}

// Version 2+
ip, err := selectPhantomImplHkdf(seed, genSubnets)
ip, err := SelectPhantomImplHkdf(seed, genSubnets)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 98adf4f

Please sign in to comment.