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

Make specific version selector functions public #271

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion pkg/phantoms/phantoms.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func parseSubnet(phantomSubnet string) (*net.IPNet, error) {
// 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 selectIPAddr(seed []byte, subnets []*phantomNet) (*PhantomIP, error) {
return selectPhantomImplHkdf(seed, subnets)
return SelectPhantomImplHkdf(seed, subnets)
}

// SelectPhantom - select one phantom IP address based on shared secret
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
Loading