More coding-style related changes

This commit is contained in:
Dmitri Dolguikh 2017-11-01 12:42:53 -07:00 committed by Dave Anderson
parent 8725ede99b
commit aa977487cd
2 changed files with 22 additions and 22 deletions

View File

@ -14,13 +14,13 @@ func TestMakeMsgAdvertise(t *testing.T) {
transactionID := [3]byte{'1', '2', '3'} transactionID := [3]byte{'1', '2', '3'}
expectedIP := net.ParseIP("2001:db8:f00f:cafe::1") expectedIP := net.ParseIP("2001:db8:f00f:cafe::1")
expectedBootFileURL := []byte("http://bootfileurl") expectedBootFileURL := []byte("http://bootfileurl")
expectedDnsServerIP := net.ParseIP("2001:db8:f00f:cafe::99") expectedDNSServerIP := net.ParseIP("2001:db8:f00f:cafe::99")
identityAssociation := &IdentityAssociation{IPAddress: expectedIP, InterfaceID: expectedInterfaceID} identityAssociation := &IdentityAssociation{IPAddress: expectedIP, InterfaceID: expectedInterfaceID}
builder := MakePacketBuilder(90, 100) builder := MakePacketBuilder(90, 100)
msg := builder.MakeMsgAdvertise(transactionID, expectedServerID, expectedClientID, 0x11, msg := builder.MakeMsgAdvertise(transactionID, expectedServerID, expectedClientID, 0x11,
[]*IdentityAssociation{identityAssociation}, expectedBootFileURL, nil, []net.IP{expectedDnsServerIP}) []*IdentityAssociation{identityAssociation}, expectedBootFileURL, nil, []net.IP{expectedDNSServerIP})
if msg.Type != MsgAdvertise { if msg.Type != MsgAdvertise {
t.Fatalf("Expected message type %d, got %d", MsgAdvertise, msg.Type) t.Fatalf("Expected message type %d, got %d", MsgAdvertise, msg.Type)
@ -67,8 +67,8 @@ func TestMakeMsgAdvertise(t *testing.T) {
if dnsServersOption == nil { if dnsServersOption == nil {
t.Fatalf("DNS servers option should be set") t.Fatalf("DNS servers option should be set")
} }
if string(dnsServersOption[0].Value) != string(expectedDnsServerIP) { if string(dnsServersOption[0].Value) != string(expectedDNSServerIP) {
t.Fatalf("Expected dns server %v, got %v", expectedDnsServerIP, net.IP(dnsServersOption[0].Value)) t.Fatalf("Expected dns server %v, got %v", expectedDNSServerIP, net.IP(dnsServersOption[0].Value))
} }
} }
@ -186,13 +186,13 @@ func TestMakeMsgReply(t *testing.T) {
transactionID := [3]byte{'1', '2', '3'} transactionID := [3]byte{'1', '2', '3'}
expectedIP := net.ParseIP("2001:db8:f00f:cafe::1") expectedIP := net.ParseIP("2001:db8:f00f:cafe::1")
expectedBootFileURL := []byte("http://bootfileurl") expectedBootFileURL := []byte("http://bootfileurl")
expectedDnsServerIP := net.ParseIP("2001:db8:f00f:cafe::99") expectedDNSServerIP := net.ParseIP("2001:db8:f00f:cafe::99")
identityAssociation := &IdentityAssociation{IPAddress: expectedIP, InterfaceID: []byte("id-1")} identityAssociation := &IdentityAssociation{IPAddress: expectedIP, InterfaceID: []byte("id-1")}
builder := MakePacketBuilder(90, 100) builder := MakePacketBuilder(90, 100)
msg := builder.MakeMsgReply(transactionID, expectedServerID, expectedClientID, 0x11, msg := builder.MakeMsgReply(transactionID, expectedServerID, expectedClientID, 0x11,
[]*IdentityAssociation{identityAssociation}, make([][]byte, 0), expectedBootFileURL, []net.IP{expectedDnsServerIP}, nil) []*IdentityAssociation{identityAssociation}, make([][]byte, 0), expectedBootFileURL, []net.IP{expectedDNSServerIP}, nil)
if msg.Type != MsgReply { if msg.Type != MsgReply {
t.Fatalf("Expected message type %d, got %d", MsgAdvertise, msg.Type) t.Fatalf("Expected message type %d, got %d", MsgAdvertise, msg.Type)
@ -240,8 +240,8 @@ func TestMakeMsgReply(t *testing.T) {
if dnsServersOption == nil { if dnsServersOption == nil {
t.Fatalf("DNS servers option should be set") t.Fatalf("DNS servers option should be set")
} }
if string(dnsServersOption[0].Value) != string(expectedDnsServerIP) { if string(dnsServersOption[0].Value) != string(expectedDNSServerIP) {
t.Fatalf("Expected dns server %v, got %v", expectedDnsServerIP, net.IP(dnsServersOption[0].Value)) t.Fatalf("Expected dns server %v, got %v", expectedDNSServerIP, net.IP(dnsServersOption[0].Value))
} }
} }
@ -349,12 +349,12 @@ func TestMakeMsgInformationRequestReply(t *testing.T) {
expectedServerID := []byte("serverid") expectedServerID := []byte("serverid")
transactionID := [3]byte{'1', '2', '3'} transactionID := [3]byte{'1', '2', '3'}
expectedBootFileURL := []byte("http://bootfileurl") expectedBootFileURL := []byte("http://bootfileurl")
expectedDnsServerIP := net.ParseIP("2001:db8:f00f:cafe::99") expectedDNSServerIP := net.ParseIP("2001:db8:f00f:cafe::99")
builder := MakePacketBuilder(90, 100) builder := MakePacketBuilder(90, 100)
msg := builder.MakeMsgInformationRequestReply(transactionID, expectedServerID, expectedClientID, 0x11, msg := builder.MakeMsgInformationRequestReply(transactionID, expectedServerID, expectedClientID, 0x11,
expectedBootFileURL, []net.IP{expectedDnsServerIP}) expectedBootFileURL, []net.IP{expectedDNSServerIP})
if msg.Type != MsgReply { if msg.Type != MsgReply {
t.Fatalf("Expected message type %d, got %d", MsgAdvertise, msg.Type) t.Fatalf("Expected message type %d, got %d", MsgAdvertise, msg.Type)
@ -397,8 +397,8 @@ func TestMakeMsgInformationRequestReply(t *testing.T) {
if dnsServersOption == nil { if dnsServersOption == nil {
t.Fatalf("DNS servers option should be set") t.Fatalf("DNS servers option should be set")
} }
if string(dnsServersOption[0].Value) != string(expectedDnsServerIP) { if string(dnsServersOption[0].Value) != string(expectedDNSServerIP) {
t.Fatalf("Expected dns server %v, got %v", expectedDnsServerIP, net.IP(dnsServersOption[0].Value)) t.Fatalf("Expected dns server %v, got %v", expectedDNSServerIP, net.IP(dnsServersOption[0].Value))
} }
} }
@ -493,10 +493,10 @@ func TestExtractLLAddressOrIdWithDUIDLLT(t *testing.T) {
func TestExtractLLAddressOrIdWithDUIDEN(t *testing.T) { func TestExtractLLAddressOrIdWithDUIDEN(t *testing.T) {
builder := &PacketBuilder{} builder := &PacketBuilder{}
expectedId := []byte{0x0, 0x1, 0x2, 0x3, 0xac, 0xbc, 0x32, 0xae, 0x86, 0x37} expectedID := []byte{0x0, 0x1, 0x2, 0x3, 0xac, 0xbc, 0x32, 0xae, 0x86, 0x37}
id := builder.ExtractLLAddressOrID([]byte{0x0, 0x2, 0x0, 0x1, 0x2, 0x3, 0xac, 0xbc, 0x32, 0xae, 0x86, 0x37}) id := builder.ExtractLLAddressOrID([]byte{0x0, 0x2, 0x0, 0x1, 0x2, 0x3, 0xac, 0xbc, 0x32, 0xae, 0x86, 0x37})
if string(expectedId) != string(id) { if string(expectedID) != string(id) {
t.Fatalf("Expected id %x, got: %x", expectedId, id) t.Fatalf("Expected id %x, got: %x", expectedID, id)
} }
} }

View File

@ -97,16 +97,16 @@ func (p *RandomAddressPool) ReserveAddresses(clientID []byte, interfaceIDs [][]b
for { for {
// we assume that ip addresses adhere to high 64 bits for net and subnet ids, low 64 bits are for host id rule // we assume that ip addresses adhere to high 64 bits for net and subnet ids, low 64 bits are for host id rule
hostOffset := randomUint64(rng) % p.poolSize hostOffset := randomUint64(rng) % p.poolSize
newIp := big.NewInt(0).Add(p.poolStartAddress, big.NewInt(0).SetUint64(hostOffset)) newIP := big.NewInt(0).Add(p.poolStartAddress, big.NewInt(0).SetUint64(hostOffset))
_, exists := p.usedIps[newIp.Uint64()]; _, exists := p.usedIps[newIP.Uint64()];
if !exists { if !exists {
timeNow := p.timeNow() timeNow := p.timeNow()
association := &IdentityAssociation{ClientID: clientID, association := &IdentityAssociation{ClientID: clientID,
InterfaceID: interfaceID, InterfaceID: interfaceID,
IPAddress: newIp.Bytes(), IPAddress: newIP.Bytes(),
CreatedAt: timeNow} CreatedAt: timeNow}
p.identityAssociations[clientIDHash] = association p.identityAssociations[clientIDHash] = association
p.usedIps[newIp.Uint64()] = struct{}{} p.usedIps[newIP.Uint64()] = struct{}{}
p.identityAssociationExpirations.Push(&AssociationExpiration{expiresAt: p.calculateAssociationExpiration(timeNow), ia: association}) p.identityAssociationExpirations.Push(&AssociationExpiration{expiresAt: p.calculateAssociationExpiration(timeNow), ia: association})
ret = append(ret, association) ret = append(ret, association)
break break
@ -121,13 +121,13 @@ func (p *RandomAddressPool) ReleaseAddresses(clientID []byte, interfaceIDs [][]
p.lock.Lock() p.lock.Lock()
defer p.lock.Unlock() defer p.lock.Unlock()
for _, interfaceId := range(interfaceIDs) { for _, interfaceID := range(interfaceIDs) {
association, exists := p.identityAssociations[p.calculateIAIDHash(clientID, interfaceId)] association, exists := p.identityAssociations[p.calculateIAIDHash(clientID, interfaceID)]
if !exists { if !exists {
continue continue
} }
delete(p.usedIps, big.NewInt(0).SetBytes(association.IPAddress).Uint64()) delete(p.usedIps, big.NewInt(0).SetBytes(association.IPAddress).Uint64())
delete(p.identityAssociations, p.calculateIAIDHash(clientID, interfaceId)) delete(p.identityAssociations, p.calculateIAIDHash(clientID, interfaceID))
} }
} }