Skip to content

Commit a31c3f1

Browse files
author
gitopia1c2zfrmhra3spfrc2m5ft64hef30guf60lvtcm3
committed
Merge pull request #27 from git-remote-gitopia/implement-fallback-provider
2 parents e8828ae + f1bfa1c commit a31c3f1

File tree

7 files changed

+65
-24
lines changed

7 files changed

+65
-24
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes will be documented here.
44

5+
## [v2.1.1] - 2025-09-16
6+
7+
- use fallback provider address when all providers are jailed
8+
59
## [v2.1.0] - 2025-09-12
610

711
- don't attempt to push if there is already a pending packfile update proposal

config/config.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@ import (
77
)
88

99
const (
10-
AppName = "git-remote-gitopia"
11-
GitopiaConfigSection = "gitopia"
12-
GitopiaConfigChainIdOption = "chainId"
13-
GitopiaConfigGRPCHostOption = "grpcHost"
14-
GitopiaConfigTmAddrOption = "tmAddr"
15-
GitopiaConfigGitServerHostOption = "gitServerHost"
16-
GitopiaConfigKeyOption = "key"
17-
GitopiaConfigBackendOption = "backend"
18-
GitopiaConfigGasPricesOption = "gasPrices"
19-
GitopiaConfigFeeGranterOption = "feeGranter"
20-
GitopiaConfigDenomOption = "denom"
10+
AppName = "git-remote-gitopia"
11+
GitopiaConfigSection = "gitopia"
12+
GitopiaConfigChainIdOption = "chainId"
13+
GitopiaConfigGRPCHostOption = "grpcHost"
14+
GitopiaConfigTmAddrOption = "tmAddr"
15+
GitopiaConfigGitServerHostOption = "gitServerHost"
16+
GitopiaConfigKeyOption = "key"
17+
GitopiaConfigBackendOption = "backend"
18+
GitopiaConfigGasPricesOption = "gasPrices"
19+
GitopiaConfigFeeGranterOption = "feeGranter"
20+
GitopiaConfigDenomOption = "denom"
21+
GitopiaConfigFallbackProviderOption = "fallbackProvider"
2122
)
2223

2324
func GitConfigGet(key string) (string, error) {
@@ -45,5 +46,8 @@ func LoadGitConfig() error {
4546
if res, err := GitConfigGet(GitopiaConfigDenomOption); err == nil {
4647
Denom = res
4748
}
49+
if res, err := GitConfigGet(GitopiaConfigFallbackProviderOption); err == nil {
50+
FallbackProvider = res
51+
}
4852
return nil
4953
}

config/config_dev.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
package config
44

55
var (
6-
ChainId = "gitopia"
7-
GasPrices = "0.001ulore"
8-
FeeGranterAddr = ""
9-
Denom = "ulore"
6+
ChainId = "gitopia"
7+
GasPrices = "0.001ulore"
8+
FeeGranterAddr = ""
9+
Denom = "ulore"
10+
FallbackProvider = ""
1011
)

config/config_prod.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
package config
44

55
var (
6-
ChainId = "gitopia"
7-
GasPrices = "0.001ulore"
8-
FeeGranterAddr = "gitopia13ashgc6j5xle4m47kqyn5psavq0u3klmscfxql"
9-
Denom = "ulore"
6+
ChainId = "gitopia"
7+
GasPrices = "0.001ulore"
8+
FeeGranterAddr = "gitopia13ashgc6j5xle4m47kqyn5psavq0u3klmscfxql"
9+
Denom = "ulore"
10+
FallbackProvider = "gitopia15nv5vf6fmww8cxr6emrzxjvj36x5n8xvsxsqpw"
1011
)

config/config_testing.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
package config
44

55
var (
6-
ChainId = "localgitopia"
7-
GasPrices = "0.001ulore"
8-
FeeGranterAddr = "gitopia12sjhqc3rqgvu3zpg8ekmwl005rp4ys58ekqg89"
9-
Denom = "ulore"
6+
ChainId = "localgitopia"
7+
GasPrices = "0.001ulore"
8+
FeeGranterAddr = "gitopia12sjhqc3rqgvu3zpg8ekmwl005rp4ys58ekqg89"
9+
Denom = "ulore"
10+
FallbackProvider = ""
1011
)

core/api/gitserver.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"net/http"
55
"time"
66

7+
"github.com/gitopia/git-remote-gitopia/config"
78
"github.com/gitopia/git-remote-gitopia/core"
89
)
910

@@ -29,7 +30,8 @@ func checkHttpHostLatency(host string) time.Duration {
2930
func GetBestGitServerHost(grpcHost string) string {
3031
providers := GetActiveStorageProviders(grpcHost)
3132
if len(providers) == 0 {
32-
return ""
33+
// No active providers found, use fallback provider if configured
34+
return GetFallbackProviderHost(grpcHost)
3335
}
3436

3537
var bestHost string
@@ -46,6 +48,17 @@ func GetBestGitServerHost(grpcHost string) string {
4648
return bestHost
4749
}
4850

51+
// GetFallbackProviderHost queries for the fallback provider's API URL using the given gRPC host
52+
func GetFallbackProviderHost(grpcHost string) string {
53+
if config.FallbackProvider != "" {
54+
provider := GetStorageProvider(grpcHost, config.FallbackProvider)
55+
if provider.ApiUrl != "" {
56+
return provider.ApiUrl
57+
}
58+
}
59+
return ""
60+
}
61+
4962
func SetConfiguredGitServerHost(host string) error {
5063
cmd := core.GitCommand("git", "config", "--global", "gitopia.gitServerHost", host)
5164
return cmd.Run()

core/api/grpc.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,20 @@ func GetActiveStorageProviders(host string) []storagetypes.Provider {
6666
}
6767
return res.Providers
6868
}
69+
70+
func GetStorageProvider(host, address string) storagetypes.Provider {
71+
conn, err := grpc.Dial(host, grpc.WithTransportCredentials(insecure.NewCredentials()))
72+
if err != nil {
73+
return storagetypes.Provider{}
74+
}
75+
defer conn.Close()
76+
77+
client := storagetypes.NewQueryClient(conn)
78+
res, err := client.Provider(context.Background(), &storagetypes.QueryProviderRequest{
79+
Address: address,
80+
})
81+
if err != nil {
82+
return storagetypes.Provider{}
83+
}
84+
return res.Provider
85+
}

0 commit comments

Comments
 (0)