Răsfoiți Sursa

go fmt simplification changes

Rod Hynes 1 an în urmă
părinte
comite
dd92f2e9b4

+ 1 - 1
psiphon/common/accesscontrol/accesscontrol_test.go

@@ -75,7 +75,7 @@ func TestAuthorization(t *testing.T) {
 	// Test: invalid key ring
 
 	invalidKeyRing := &VerificationKeyRing{
-		Keys: []*VerificationKey{&VerificationKey{}},
+		Keys: []*VerificationKey{{}},
 	}
 
 	err = ValidateVerificationKeyRing(invalidKeyRing)

+ 1 - 1
psiphon/common/packetman/packetman.go

@@ -173,7 +173,7 @@ type compiledSpec struct {
 func compileSpec(spec *Spec) (*compiledSpec, error) {
 
 	compiledPacketSpecs := make([][]transformation, len(spec.PacketSpecs))
-	for i, _ := range spec.PacketSpecs {
+	for i := range spec.PacketSpecs {
 		compiledPacketSpecs[i] = make([]transformation, len(spec.PacketSpecs[i]))
 		for j, transformationSpec := range spec.PacketSpecs[i] {
 			transform, err := compileTransformation(transformationSpec)

+ 1 - 1
psiphon/common/packetman/packetman_linux_test.go

@@ -85,7 +85,7 @@ func testPacketManipulator(useIPv6 bool, t *testing.T) {
 	config := &Config{
 		Logger:        newTestLogger(),
 		ProtocolPorts: []int{listenerPort},
-		Specs:         []*Spec{&Spec{Name: testSpecName, PacketSpecs: [][]string{[]string{"TCP-flags S"}}}},
+		Specs:         []*Spec{{Name: testSpecName, PacketSpecs: [][]string{{"TCP-flags S"}}}},
 		SelectSpecName: func(protocolPort int, _ net.IP) (string, interface{}) {
 			if protocolPort == listenerPort {
 				return testSpecName, extraDataValue

+ 10 - 10
psiphon/common/packetman/packetman_test.go

@@ -110,10 +110,10 @@ func TestTransformations(t *testing.T) {
 		SYN: true,
 		ACK: true,
 		Options: []layers.TCPOption{
-			layers.TCPOption{OptionType: layers.TCPOptionKindNop, OptionLength: 1},
-			layers.TCPOption{OptionType: layers.TCPOptionKindSACKPermitted, OptionLength: 2},
-			layers.TCPOption{OptionType: layers.TCPOptionKindSACK, OptionLength: 10, OptionData: bytes.Repeat([]byte{0}, 8)},
-			layers.TCPOption{OptionType: layers.TCPOptionKindTimestamps, OptionLength: 10, OptionData: bytes.Repeat([]byte{0}, 8)},
+			{OptionType: layers.TCPOptionKindNop, OptionLength: 1},
+			{OptionType: layers.TCPOptionKindSACKPermitted, OptionLength: 2},
+			{OptionType: layers.TCPOptionKindSACK, OptionLength: 10, OptionData: bytes.Repeat([]byte{0}, 8)},
+			{OptionType: layers.TCPOptionKindTimestamps, OptionLength: 10, OptionData: bytes.Repeat([]byte{0}, 8)},
 		},
 	}
 
@@ -219,12 +219,12 @@ repeatLoop:
 				// omitted.
 
 				expectedOptions := []layers.TCPOption{
-					layers.TCPOption{OptionType: layers.TCPOptionKindSACKPermitted, OptionLength: 2},
-					layers.TCPOption{OptionType: layers.TCPOptionKindSACK, OptionLength: 10, OptionData: bytes.Repeat([]byte{0xff}, 8)},
-					layers.TCPOption{OptionType: layers.TCPOptionKindTimestamps, OptionLength: 10, OptionData: bytes.Repeat([]byte{0xff}, 8)},
-					layers.TCPOption{OptionType: layers.TCPOptionKindMSS, OptionLength: 4, OptionData: bytes.Repeat([]byte{0xff}, 2)},
-					layers.TCPOption{OptionType: layers.TCPOptionKindWindowScale, OptionLength: 3, OptionData: bytes.Repeat([]byte{0xff}, 1)},
-					layers.TCPOption{OptionType: layers.TCPOptionKindEndList, OptionLength: 1},
+					{OptionType: layers.TCPOptionKindSACKPermitted, OptionLength: 2},
+					{OptionType: layers.TCPOptionKindSACK, OptionLength: 10, OptionData: bytes.Repeat([]byte{0xff}, 8)},
+					{OptionType: layers.TCPOptionKindTimestamps, OptionLength: 10, OptionData: bytes.Repeat([]byte{0xff}, 8)},
+					{OptionType: layers.TCPOptionKindMSS, OptionLength: 4, OptionData: bytes.Repeat([]byte{0xff}, 2)},
+					{OptionType: layers.TCPOptionKindWindowScale, OptionLength: 3, OptionData: bytes.Repeat([]byte{0xff}, 1)},
+					{OptionType: layers.TCPOptionKindEndList, OptionLength: 1},
 				}
 
 				if tcp.SrcPort != 0xffff ||

+ 1 - 1
psiphon/common/parameters/portlist.go

@@ -31,7 +31,7 @@ type TunnelProtocolPortLists map[string]*common.PortList
 
 // Validate checks that tunnel protocol names are valid.
 func (lists TunnelProtocolPortLists) Validate() error {
-	for tunnelProtocol, _ := range lists {
+	for tunnelProtocol := range lists {
 		if tunnelProtocol != protocol.TUNNEL_PROTOCOLS_ALL &&
 			!common.Contains(protocol.SupportedTunnelProtocols, tunnelProtocol) {
 			return errors.TraceNew("invalid tunnel protocol for port list")

+ 3 - 3
psiphon/common/sss/polynomial_test.go

@@ -78,9 +78,9 @@ func TestGenerateFullSize(t *testing.T) {
 
 func TestInterpolate(t *testing.T) {
 	in := []pair{
-		pair{x: 1, y: 1},
-		pair{x: 2, y: 2},
-		pair{x: 3, y: 3},
+		{x: 1, y: 1},
+		{x: 2, y: 2},
+		{x: 3, y: 3},
 	}
 
 	if v, want := interpolate(in, 0), byte(0); v != want {

+ 5 - 5
psiphon/common/values/values.go

@@ -331,11 +331,11 @@ func generateUserAgent() string {
 		}
 
 		userAgentGenerators = []*userAgentGenerator{
-			&userAgentGenerator{chromeVersion, makeGenerator("Mozilla/5\\.0 \\(Macintosh; Intel Mac OS X 1[01]_(1|)[0-5]\\) AppleWebKit/537\\.36 \\(KHTML, like Gecko\\) Chrome/__VER__ Safari/537\\.36")},
-			&userAgentGenerator{chromeVersion, makeGenerator("Mozilla/5\\.0 \\(Windows NT 1(0|0|1)\\.0; (WOW64|Win64)(; x64|; x64|)\\) AppleWebKit/537\\.36 \\(KHTML, like Gecko\\) Chrome/__VER__ Safari/537\\.36")},
-			&userAgentGenerator{chromeVersion, makeGenerator("Mozilla/5\\.0 \\(Linux; Android (9|10|10|11|12); [a-zA-Z0-9_]{5,10}\\) AppleWebKit/537\\.36 \\(KHTML, like Gecko\\) Chrome/__VER__ Mobile Safari/537\\.36")},
-			&userAgentGenerator{safariVersion, makeGenerator("Mozilla/5\\.0 \\(iPhone; CPU iPhone OS 1[3-5]_[1-5] like Mac OS X\\) AppleWebKit/(__VER__|__VER__|600\\.[1-8]\\.[12][0-7]|537\\.36) \\(KHTML, like Gecko\\) Version/1[0-4]\\.[0-7](\\.[1-9][0-7]|) Mobile/[A-Z0-9]{6} Safari/__VER__")},
-			&userAgentGenerator{safariVersion, makeGenerator("Mozilla/5\\.0 \\(Macintosh; Intel Mac OS X 1[01]_(1|)[0-7](_[1-7]|)\\) AppleWebKit/(__VER__|__VER__|600\\.[1-8]\\.[12][0-7]|537\\.36) \\(KHTML, like Gecko\\) Version/1[0-4]\\.[0-7](\\.[1-9][0-7]|) Safari/__VER__")},
+			{chromeVersion, makeGenerator("Mozilla/5\\.0 \\(Macintosh; Intel Mac OS X 1[01]_(1|)[0-5]\\) AppleWebKit/537\\.36 \\(KHTML, like Gecko\\) Chrome/__VER__ Safari/537\\.36")},
+			{chromeVersion, makeGenerator("Mozilla/5\\.0 \\(Windows NT 1(0|0|1)\\.0; (WOW64|Win64)(; x64|; x64|)\\) AppleWebKit/537\\.36 \\(KHTML, like Gecko\\) Chrome/__VER__ Safari/537\\.36")},
+			{chromeVersion, makeGenerator("Mozilla/5\\.0 \\(Linux; Android (9|10|10|11|12); [a-zA-Z0-9_]{5,10}\\) AppleWebKit/537\\.36 \\(KHTML, like Gecko\\) Chrome/__VER__ Mobile Safari/537\\.36")},
+			{safariVersion, makeGenerator("Mozilla/5\\.0 \\(iPhone; CPU iPhone OS 1[3-5]_[1-5] like Mac OS X\\) AppleWebKit/(__VER__|__VER__|600\\.[1-8]\\.[12][0-7]|537\\.36) \\(KHTML, like Gecko\\) Version/1[0-4]\\.[0-7](\\.[1-9][0-7]|) Mobile/[A-Z0-9]{6} Safari/__VER__")},
+			{safariVersion, makeGenerator("Mozilla/5\\.0 \\(Macintosh; Intel Mac OS X 1[01]_(1|)[0-7](_[1-7]|)\\) AppleWebKit/(__VER__|__VER__|600\\.[1-8]\\.[12][0-7]|537\\.36) \\(KHTML, like Gecko\\) Version/1[0-4]\\.[0-7](\\.[1-9][0-7]|) Safari/__VER__")},
 		}
 	}
 

+ 2 - 2
psiphon/config_test.go

@@ -521,7 +521,7 @@ func LoadConfigMigrateTest(oslDirChildrenPreMigration []FileTree, oslDirChildren
 	// The set of expected file paths and set of actual  file paths should be
 	// identical.
 
-	for k, _ := range expectedTestDirectoryFilePaths {
+	for k := range expectedTestDirectoryFilePaths {
 		_, ok := testDirectoryFilePaths[k]
 		if ok {
 			// Prevent redundant checks
@@ -531,7 +531,7 @@ func LoadConfigMigrateTest(oslDirChildrenPreMigration []FileTree, oslDirChildren
 		}
 	}
 
-	for k, _ := range testDirectoryFilePaths {
+	for k := range testDirectoryFilePaths {
 		if _, ok := expectedTestDirectoryFilePaths[k]; !ok {
 			suite.T().Errorf("%s in directory but not expected", k)
 		}

+ 2 - 2
psiphon/inproxy_test.go

@@ -78,11 +78,11 @@ func runInproxyBrokerDialParametersTest() error {
 	publicKey, _ := privateKey.GetPublicKey()
 	obfuscationSecret, _ := inproxy.GenerateRootObfuscationSecret()
 	brokerSpecs := []*parameters.InproxyBrokerSpec{
-		&parameters.InproxyBrokerSpec{
+		{
 			BrokerPublicKey:             publicKey.String(),
 			BrokerRootObfuscationSecret: obfuscationSecret.String(),
 			BrokerFrontingSpecs: []*parameters.FrontingSpec{
-				&parameters.FrontingSpec{
+				{
 					FrontingProviderID: prng.HexString(8),
 					Addresses:          []string{addressRegex},
 					VerifyServerName:   "example.org",

+ 2 - 2
psiphon/server/config.go

@@ -611,7 +611,7 @@ func LoadConfig(configJSON []byte) (*Config, error) {
 		// at most one meek tunnel protocol to be configured so all
 		// connections to the broker use the same, unambiguous instance.
 		meekServerCount := 0
-		for tunnelProtocol, _ := range config.TunnelProtocolPorts {
+		for tunnelProtocol := range config.TunnelProtocolPorts {
 			if protocol.TunnelProtocolUsesMeek(tunnelProtocol) {
 				meekServerCount += 1
 			}
@@ -627,7 +627,7 @@ func LoadConfig(configJSON []byte) (*Config, error) {
 		}
 	}
 
-	for tunnelProtocol, _ := range config.TunnelProtocolPorts {
+	for tunnelProtocol := range config.TunnelProtocolPorts {
 		if !common.Contains(protocol.SupportedTunnelProtocols, tunnelProtocol) {
 			return nil, errors.Tracef("Unsupported tunnel protocol: %s", tunnelProtocol)
 		}

+ 1 - 1
psiphon/server/discovery/classic_test.go

@@ -62,7 +62,7 @@ func TestDiscoveryBuckets(t *testing.T) {
 	for i := 0; i < 105; i++ {
 		servers = append(servers, &psinet.DiscoveryServer{
 			EncodedServerEntry: strconv.Itoa(i),
-			DiscoveryDateRange: []time.Time{time.Time{}, time.Now()},
+			DiscoveryDateRange: []time.Time{{}, time.Now()},
 		})
 	}
 

+ 18 - 18
psiphon/server/server_test.go

@@ -2581,11 +2581,11 @@ func checkExpectedServerTunnelLogFields(
 			return fmt.Errorf("unexpected field value %s: '%v'", name, fields[name])
 		}
 		for _, pair := range [][]string{
-			[]string{"dest_bytes_up_tcp", "bytes_up_tcp"},
-			[]string{"dest_bytes_down_tcp", "bytes_down_tcp"},
-			[]string{"dest_bytes_up_udp", "bytes_up_udp"},
-			[]string{"dest_bytes_down_udp", "bytes_down_udp"},
-			[]string{"dest_bytes", "bytes"},
+			{"dest_bytes_up_tcp", "bytes_up_tcp"},
+			{"dest_bytes_down_tcp", "bytes_down_tcp"},
+			{"dest_bytes_up_udp", "bytes_up_udp"},
+			{"dest_bytes_down_udp", "bytes_down_udp"},
+			{"dest_bytes", "bytes"},
 		} {
 			value0 := int64(fields[pair[0]].(float64))
 			value1 := int64(fields[pair[1]].(float64))
@@ -3675,19 +3675,19 @@ func initializePruneServerEntriesTest(
 	// - DialPort0: set dial port to 0, a special prune case (see statusAPIRequestHandler)
 
 	pruneServerEntryTestCases := []*pruneServerEntryTestCase{
-		&pruneServerEntryTestCase{IPAddress: "192.0.2.1", ExplicitTag: true, LocalTimestamp: newTimeStamp, PsinetValid: true, ExpectPrune: false},
-		&pruneServerEntryTestCase{IPAddress: "192.0.2.2", ExplicitTag: false, LocalTimestamp: newTimeStamp, PsinetValid: true, ExpectPrune: false},
-		&pruneServerEntryTestCase{IPAddress: "192.0.2.3", ExplicitTag: true, LocalTimestamp: oldTimeStamp, PsinetValid: true, ExpectPrune: false},
-		&pruneServerEntryTestCase{IPAddress: "192.0.2.4", ExplicitTag: false, LocalTimestamp: oldTimeStamp, PsinetValid: true, ExpectPrune: false},
-		&pruneServerEntryTestCase{IPAddress: "192.0.2.5", ExplicitTag: true, LocalTimestamp: newTimeStamp, PsinetValid: false, ExpectPrune: false},
-		&pruneServerEntryTestCase{IPAddress: "192.0.2.6", ExplicitTag: false, LocalTimestamp: newTimeStamp, PsinetValid: false, ExpectPrune: false},
-		&pruneServerEntryTestCase{IPAddress: "192.0.2.7", ExplicitTag: true, LocalTimestamp: oldTimeStamp, PsinetValid: false, ExpectPrune: true, IsEmbedded: false},
-		&pruneServerEntryTestCase{IPAddress: "192.0.2.8", ExplicitTag: false, LocalTimestamp: oldTimeStamp, PsinetValid: false, ExpectPrune: true, IsEmbedded: false},
-		&pruneServerEntryTestCase{IPAddress: "192.0.2.9", ExplicitTag: true, LocalTimestamp: oldTimeStamp, PsinetValid: false, ExpectPrune: true, IsEmbedded: true},
-		&pruneServerEntryTestCase{IPAddress: "192.0.2.10", ExplicitTag: false, LocalTimestamp: oldTimeStamp, PsinetValid: false, ExpectPrune: true, IsEmbedded: true},
-		&pruneServerEntryTestCase{IPAddress: "192.0.2.11", ExplicitTag: true, LocalTimestamp: oldTimeStamp, PsinetValid: true, ExpectPrune: true, IsEmbedded: false, DialPort0: true},
-		&pruneServerEntryTestCase{IPAddress: "192.0.2.12", ExplicitTag: false, LocalTimestamp: oldTimeStamp, PsinetValid: true, ExpectPrune: true, IsEmbedded: true, DialPort0: true},
-		&pruneServerEntryTestCase{IPAddress: "192.0.2.13", ExplicitTag: true, LocalTimestamp: oldTimeStamp, PsinetValid: true, ExpectPrune: true, IsEmbedded: true, DialPort0: true},
+		{IPAddress: "192.0.2.1", ExplicitTag: true, LocalTimestamp: newTimeStamp, PsinetValid: true, ExpectPrune: false},
+		{IPAddress: "192.0.2.2", ExplicitTag: false, LocalTimestamp: newTimeStamp, PsinetValid: true, ExpectPrune: false},
+		{IPAddress: "192.0.2.3", ExplicitTag: true, LocalTimestamp: oldTimeStamp, PsinetValid: true, ExpectPrune: false},
+		{IPAddress: "192.0.2.4", ExplicitTag: false, LocalTimestamp: oldTimeStamp, PsinetValid: true, ExpectPrune: false},
+		{IPAddress: "192.0.2.5", ExplicitTag: true, LocalTimestamp: newTimeStamp, PsinetValid: false, ExpectPrune: false},
+		{IPAddress: "192.0.2.6", ExplicitTag: false, LocalTimestamp: newTimeStamp, PsinetValid: false, ExpectPrune: false},
+		{IPAddress: "192.0.2.7", ExplicitTag: true, LocalTimestamp: oldTimeStamp, PsinetValid: false, ExpectPrune: true, IsEmbedded: false},
+		{IPAddress: "192.0.2.8", ExplicitTag: false, LocalTimestamp: oldTimeStamp, PsinetValid: false, ExpectPrune: true, IsEmbedded: false},
+		{IPAddress: "192.0.2.9", ExplicitTag: true, LocalTimestamp: oldTimeStamp, PsinetValid: false, ExpectPrune: true, IsEmbedded: true},
+		{IPAddress: "192.0.2.10", ExplicitTag: false, LocalTimestamp: oldTimeStamp, PsinetValid: false, ExpectPrune: true, IsEmbedded: true},
+		{IPAddress: "192.0.2.11", ExplicitTag: true, LocalTimestamp: oldTimeStamp, PsinetValid: true, ExpectPrune: true, IsEmbedded: false, DialPort0: true},
+		{IPAddress: "192.0.2.12", ExplicitTag: false, LocalTimestamp: oldTimeStamp, PsinetValid: true, ExpectPrune: true, IsEmbedded: true, DialPort0: true},
+		{IPAddress: "192.0.2.13", ExplicitTag: true, LocalTimestamp: oldTimeStamp, PsinetValid: true, ExpectPrune: true, IsEmbedded: true, DialPort0: true},
 	}
 
 	for _, testCase := range pruneServerEntryTestCases {

+ 1 - 1
psiphon/server/tunnelServer.go

@@ -423,7 +423,7 @@ func newSSHServer(
 	var inproxyBrokerSessions *inproxy.ServerBrokerSessions
 
 	runningInproxy := false
-	for tunnelProtocol, _ := range support.Config.TunnelProtocolPorts {
+	for tunnelProtocol := range support.Config.TunnelProtocolPorts {
 		if protocol.TunnelProtocolUsesInproxy(tunnelProtocol) {
 			runningInproxy = true
 			break