|
| 1 | +package mg12 |
| 2 | + |
| 3 | +import ( |
| 4 | + log "github.com/ipfs/fs-repo-migrations/tools/stump" |
| 5 | +) |
| 6 | + |
| 7 | +// convertRouting converts Routing.Type to implicit default |
| 8 | +// https://github.com/ipfs/kubo/pull/9475 |
| 9 | +func convertRouting(confMap map[string]any) { |
| 10 | + routing, _ := confMap["Routing"].(map[string]any) |
| 11 | + if routing == nil { |
| 12 | + log.Log("No Routing field in config, skipping") |
| 13 | + return |
| 14 | + } |
| 15 | + |
| 16 | + rType, ok := routing["Type"].(string) |
| 17 | + if !ok { |
| 18 | + log.Log("No Routing.Type field in config, skipping") |
| 19 | + return |
| 20 | + } |
| 21 | + if rType == "dht" || rType == "" { |
| 22 | + delete(routing, "Type") |
| 23 | + } else { |
| 24 | + log.Log("Routing.Type settings is different than the old default, skipping") |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +// convertReprovider converts Reprovider to implicit defaults |
| 29 | +// https://github.com/ipfs/kubo/pull/9326 |
| 30 | +func convertReprovider(confMap map[string]any) { |
| 31 | + reprovider, _ := confMap["Reprovider"].(map[string]any) |
| 32 | + if reprovider == nil { |
| 33 | + log.Log("No Reprovider field in config, skipping") |
| 34 | + return |
| 35 | + } |
| 36 | + |
| 37 | + interval, ok := reprovider["Interval"].(string) |
| 38 | + if !ok { |
| 39 | + log.Log("No Reprovider.Interval field in config, skipping") |
| 40 | + return |
| 41 | + } |
| 42 | + if interval == "12h" { |
| 43 | + delete(reprovider, "Interval") |
| 44 | + } else { |
| 45 | + log.Log("Reprovider.Interval settings is different than the old default, skipping") |
| 46 | + } |
| 47 | + |
| 48 | + strategy, ok := reprovider["Strategy"].(string) |
| 49 | + if !ok { |
| 50 | + log.Log("No Reprovider.Strategy field in config, skipping") |
| 51 | + return |
| 52 | + } |
| 53 | + if strategy == "all" { |
| 54 | + delete(reprovider, "Strategy") |
| 55 | + } else { |
| 56 | + log.Log("Reprovider.Strategy settings is different than the old default, skipping") |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +// convertConnMgr converts Swarm.ConnMgr to implicit defaults |
| 61 | +// https://github.com/ipfs/kubo/pull/9467 |
| 62 | +func convertConnMgr(confMap map[string]any) { |
| 63 | + swarm, _ := confMap["Swarm"].(map[string]any) |
| 64 | + if swarm == nil { |
| 65 | + log.Log("No Swarm field in config, skipping") |
| 66 | + return |
| 67 | + } |
| 68 | + connmgr, _ := swarm["ConnMgr"].(map[string]any) |
| 69 | + if connmgr == nil { |
| 70 | + log.Log("No Swarm.ConnMgr field in config, skipping") |
| 71 | + return |
| 72 | + } |
| 73 | + cmType, ok := connmgr["Type"].(string) |
| 74 | + if !ok { |
| 75 | + log.Log("No Swarm.ConnMgr.Type field in config, skipping") |
| 76 | + return |
| 77 | + } |
| 78 | + cmLowWater, ok := connmgr["LowWater"].(float64) |
| 79 | + if !ok { |
| 80 | + log.Log("No Swarm.ConnMgr.LowWater field in config, skipping") |
| 81 | + return |
| 82 | + } |
| 83 | + cmHighWater, ok := connmgr["HighWater"].(float64) |
| 84 | + if !ok { |
| 85 | + log.Log("No Swarm.ConnMgr.HighWater field in config, skipping") |
| 86 | + return |
| 87 | + } |
| 88 | + cmGrace, ok := connmgr["GracePeriod"].(string) |
| 89 | + if !ok { |
| 90 | + log.Log("No Swarm.ConnMgr.GracePeriod field in config, skipping") |
| 91 | + return |
| 92 | + } |
| 93 | + |
| 94 | + if cmType == "basic" { |
| 95 | + delete(connmgr, "Type") |
| 96 | + if cmGrace == "20s" { |
| 97 | + delete(connmgr, "GracePeriod") |
| 98 | + } else { |
| 99 | + log.Log("Swarm.ConnMgr.GracePeriod setting are different than the old defaults, skipping") |
| 100 | + } |
| 101 | + if int(cmLowWater) == 600 && int(cmHighWater) == 900 { |
| 102 | + delete(connmgr, "LowWater") |
| 103 | + delete(connmgr, "HighWater") |
| 104 | + } else { |
| 105 | + log.Log("Swarm.ConnMgr Low/HighWater settings are different than the old defaults, skipping") |
| 106 | + } |
| 107 | + } else { |
| 108 | + log.Log("Swarm.ConnMgr settings are different than the old defaults, skipping") |
| 109 | + } |
| 110 | +} |
0 commit comments