Skip to content

Commit 315e486

Browse files
committed
refactor: better var names
1 parent 939c1d1 commit 315e486

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

ipfs-9-to-10/migration/config_conv.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var (
2121
type convArray func([]string) []string
2222

2323
// convertFile converts a config file from one version to another
24-
func convertFile(orig string, new string, quicEnabled bool, convBootstrap convArray, convSwarm convArray) error {
24+
func convertFile(orig string, new string, enableQuic bool, convBootstrap convArray, convSwarm convArray) error {
2525
in, err := os.Open(orig)
2626
if err != nil {
2727
return err
@@ -30,11 +30,11 @@ func convertFile(orig string, new string, quicEnabled bool, convBootstrap convAr
3030
if err != nil {
3131
return err
3232
}
33-
return convert(in, out, quicEnabled, convBootstrap, convSwarm)
33+
return convert(in, out, enableQuic, convBootstrap, convSwarm)
3434
}
3535

3636
// convert converts the config from one version to another
37-
func convert(in io.Reader, out io.Writer, quicEnabled bool, convBootstrap convArray, convSwarm convArray) error {
37+
func convert(in io.Reader, out io.Writer, enableQuic bool, convBootstrap convArray, convSwarm convArray) error {
3838
data, err := ioutil.ReadAll(in)
3939
if err != nil {
4040
return err
@@ -48,7 +48,7 @@ func convert(in io.Reader, out io.Writer, quicEnabled bool, convBootstrap convAr
4848
convertBootstrap(confMap, convBootstrap)
4949

5050
// Convert swarm config
51-
if quicEnabled {
51+
if enableQuic {
5252
// When enabling quic
5353
// - Remove experimental option from config
5454
confEnabled, ok := removeExperimentalQuic(confMap)
@@ -70,6 +70,7 @@ func convert(in io.Reader, out io.Writer, quicEnabled bool, convBootstrap convAr
7070
return nil
7171
}
7272

73+
// Remove Experimental.QUIC flag
7374
func removeExperimentalQuic(confMap map[string]interface{}) (bool, bool) {
7475
confExpi := confMap["Experimental"].(map[string]interface{})
7576
if confExpi == nil {
@@ -83,6 +84,7 @@ func removeExperimentalQuic(confMap map[string]interface{}) (bool, bool) {
8384
return enabled, ok
8485
}
8586

87+
// Convert Bootstrap addresses to/from QUIC
8688
func convertBootstrap(confMap map[string]interface{}, conv convArray) {
8789
bootstrapi, _ := confMap["Bootstrap"].([]interface{})
8890
if bootstrapi == nil {
@@ -96,6 +98,7 @@ func convertBootstrap(confMap map[string]interface{}, conv convArray) {
9698
confMap["Bootstrap"] = conv(bootstrap)
9799
}
98100

101+
// Convert Addresses.Swarm to/from QUIC
99102
func convertSwarm(confMap map[string]interface{}, conv convArray) {
100103
addressesi, _ := confMap["Addresses"].(map[string]interface{})
101104
if addressesi == nil {
@@ -116,6 +119,7 @@ func convertSwarm(confMap map[string]interface{}, conv convArray) {
116119
addressesi["Swarm"] = conv(swarm)
117120
}
118121

122+
// Add QUIC Bootstrap address
119123
func ver9to10Bootstrap(bootstrap []string) []string {
120124
hasOld := false
121125
hasNew := false
@@ -145,6 +149,7 @@ func ver10to9Bootstrap(bootstrap []string) []string {
145149

146150
var tcpRegexp = regexp.MustCompile(`/tcp/([0-9]+)`)
147151

152+
// For each TCP listener, add a QUIC listener
148153
func ver9to10Swarm(swarm []string) []string {
149154
res := make([]string, 0, len(swarm)*2)
150155
for _, addr := range swarm {
@@ -170,6 +175,7 @@ func ver9to10Swarm(swarm []string) []string {
170175

171176
var quicRegexp = regexp.MustCompile(`/udp/[0-9]+/quic`)
172177

178+
// Remove QUIC listeners
173179
func ver10to9Swarm(swarm []string) []string {
174180
// Remove quic addresses
175181
res := make([]string, 0, len(swarm))

0 commit comments

Comments
 (0)