forked from solana-labs/solana-ping-api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrpcEndpoint.go
44 lines (34 loc) · 792 Bytes
/
rpcEndpoint.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"sort"
"sync"
)
type RpcEndpointPool []RpcEndpoint
var RetryMutex sync.Mutex
type RpcEndpoint struct {
Piority int
Host string
Retry int
}
func (r RpcEndpointPool) Len() int { return len(r) }
func (r RpcEndpointPool) Swap(i, j int) { r[i], r[j] = r[j], r[i] }
func (r RpcEndpointPool) Less(i, j int) bool { return r[i].Piority < r[j].Piority }
func sortEndpoint(endpoints []RpcEndpoint) {
sort.Sort(RpcEndpointPool(endpoints))
}
func (r *RpcEndpoint) GoNext(max_retry int) bool {
if r.Retry < max_retry {
return false
}
return true
}
func (r *RpcEndpoint) AddRetry() {
RetryMutex.Lock()
defer RetryMutex.Unlock()
r.Retry += 1
}
func (r *RpcEndpoint) ResetRetry() {
RetryMutex.Lock()
defer RetryMutex.Unlock()
r.Retry = 0
}