Skip to content

Commit

Permalink
Fix Compile Errors For Networking
Browse files Browse the repository at this point in the history
  • Loading branch information
tholonious committed Feb 22, 2024
1 parent 91f7302 commit e0897e9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 28 deletions.
15 changes: 8 additions & 7 deletions apis/eth_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/golang/glog"
"github.com/montanaflynn/stats"
"io/ioutil"
"net/http"
"strconv"

"github.com/golang/glog"
"github.com/montanaflynn/stats"
)

type CoinbaseResponse struct {
Expand Down Expand Up @@ -194,7 +195,7 @@ func GetUSDToETHPrice() (float64, error) {
amount, err := getCoinbasePrice()
if err != nil {
// The amount will be zero in this case, which is fine
glog.Errorf("Error fetching Coinbase price: %v", err)
glog.V(2).Infof("Error fetching Coinbase price: %v", err)
}

if amount != 0 {
Expand All @@ -205,7 +206,7 @@ func GetUSDToETHPrice() (float64, error) {
amount, err := getCoingeckoPrice()
if err != nil {
// The amount will be zero in this case, which is fine
glog.Errorf("Error fetching Coingecko price: %v", err)
glog.V(2).Infof("Error fetching Coingecko price: %v", err)
}

if amount != 0 {
Expand All @@ -216,7 +217,7 @@ func GetUSDToETHPrice() (float64, error) {
amount, err := getBlockchainDotcomPrice()
if err != nil {
// The amount will be zero in this case, which is fine
glog.Errorf("Error fetching blockchain.com price: %v", err)
glog.V(2).Infof("Error fetching blockchain.com price: %v", err)
}

if amount != 0 {
Expand All @@ -227,7 +228,7 @@ func GetUSDToETHPrice() (float64, error) {
amount, err := getGeminiPrice()
if err != nil {
// The amount will be zero in this case, which is fine
glog.Errorf("Error fetching Gemini price: %v", err)
glog.V(2).Infof("Error fetching Gemini price: %v", err)
}

if amount != 0 {
Expand All @@ -238,7 +239,7 @@ func GetUSDToETHPrice() (float64, error) {
amount, err := getKrakenPrice()
if err != nil {
// The amount will be zero in this case, which is fine
glog.Errorf("Error fetching Kraken price: %v", err)
glog.V(2).Infof("Error fetching Kraken price: %v", err)
}

if amount != 0 {
Expand Down
18 changes: 9 additions & 9 deletions routes/admin_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (fes *APIServer) _handleNodeControlGetInfo(
existingDeSoPeers[currentPeerRes.IP+fmt.Sprintf(":%d", currentPeerRes.ProtocolPort)] = true
}
// Return some deso addrs from the addr manager.
desoAddrs := fes.backendServer.GetConnectionManager().GetAddrManager().AddressCache()
desoAddrs := fes.backendServer.AddrMgr.AddressCache()
sort.Slice(desoAddrs, func(ii, jj int) bool {
// Use a hash to get a random but deterministic ordering.
hashI := string(lib.Sha256DoubleHash([]byte(desoAddrs[ii].IP.String() + fmt.Sprintf(":%d", desoAddrs[ii].Port)))[:])
Expand Down Expand Up @@ -239,12 +239,12 @@ func (fes *APIServer) _handleConnectDeSoNode(
// increasing retry delay, but we should still clean it up at some point.
connectPeerDone := make(chan bool)
go func() {
netAddr, err := fes.backendServer.GetConnectionManager().GetAddrManager().HostToNetAddress(ip, protocolPort, 0)
netAddr, err := fes.backendServer.AddrMgr.HostToNetAddress(ip, protocolPort, 0)
if err != nil {
_AddBadRequestError(ww, fmt.Sprintf("_handleConnectDeSoNode: Cannot connect to node %s:%d: %v", ip, protocolPort, err))
return
}
fes.backendServer.GetConnectionManager().ConnectPeer(nil, netAddr)
fes.backendServer.GetNetworkManager().CreateNonValidatorOutboundConnection(ip)

// Spin until the peer shows up in the connection manager or until 100 iterations.
// Note the pause between each iteration.
Expand Down Expand Up @@ -274,7 +274,7 @@ func (fes *APIServer) _handleConnectDeSoNode(
// At this point the peer shoud be connected. Add their address to the addrmgr
// in case the user wants to connect again in the future. Set the source to be
// the address itself since we don't have anything else.
fes.backendServer.GetConnectionManager().GetAddrManager().AddAddress(netAddr, netAddr)
fes.backendServer.AddrMgr.AddAddress(netAddr, netAddr)

connectPeerDone <- true
return
Expand Down Expand Up @@ -320,13 +320,13 @@ func (fes *APIServer) _handleDisconnectDeSoNode(

// Manually remove the peer from the connection manager and mark it as such
// so that the connection manager won't reconnect to it or replace it.
fes.backendServer.GetConnectionManager().RemovePeer(peerFound)
peerFound.PeerManuallyRemovedFromConnectionManager = true

peerFound.Disconnect()
remoteNode := fes.backendServer.GetNetworkManager().GetRemoteNodeManager().GetRemoteNodeFromPeer(peerFound)
if remoteNode != nil {
fes.backendServer.GetNetworkManager().GetRemoteNodeManager().Disconnect(remoteNode)
}

res := NodeControlResponse{
// Return an empty response, which indicates we set the peer up to be connected.
// Return an empty response, which indicates we set the peer up to be disconnected.
}
if err := json.NewEncoder(ww).Encode(res); err != nil {
_AddBadRequestError(ww, fmt.Sprintf("NodeControl: Problem encoding response as JSON: %v", err))
Expand Down
10 changes: 5 additions & 5 deletions routes/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ func (fes *APIServer) GetBlockchainDotComExchangeRate() (_exchangeRate float64,
url := "https://api.blockchain.com/v3/exchange/tickers/CLOUT-USD"
req, err := http.NewRequest("GET", url, nil)
if err != nil {
glog.Errorf("GetBlockchainDotComExchangeRate: Problem creating request: %v", err)
glog.V(2).Infof("GetBlockchainDotComExchangeRate: Problem creating request: %v", err)
continue
}
req.Header.Set("Content-Type", "application/json")

resp, err := httpClient.Do(req)
if err != nil {
glog.Errorf("GetBlockchainDotComExchangeRate: Problem with HTTP request %s: %v", url, err)
glog.V(2).Infof("GetBlockchainDotComExchangeRate: Problem with HTTP request %s: %v", url, err)
continue
}
defer resp.Body.Close()
Expand All @@ -167,7 +167,7 @@ func (fes *APIServer) GetBlockchainDotComExchangeRate() (_exchangeRate float64,
responseData := &BlockchainDeSoTickerResponse{}
decoder := json.NewDecoder(bytes.NewReader(body))
if err = decoder.Decode(responseData); err != nil {
glog.Errorf("GetBlockchainDotComExchangeRate: Problem decoding response JSON into "+
glog.V(2).Infof("GetBlockchainDotComExchangeRate: Problem decoding response JSON into "+
"interface %v, response: %v, error: %v", responseData, resp, err)
continue
}
Expand All @@ -179,13 +179,13 @@ func (fes *APIServer) GetBlockchainDotComExchangeRate() (_exchangeRate float64,
}
blockchainDotComExchangeRate, err := stats.Max(exchangeRatesFetched)
if err != nil {
glog.Errorf("GetBlockchainDotComExchangeRate: Problem getting max from list of float64s: %v", err)
glog.V(2).Infof("GetBlockchainDotComExchangeRate: Problem getting max from list of float64s: %v", err)
return 0, err
}
glog.V(2).Infof("Blockchain exchange rate: %v %v", blockchainDotComExchangeRate, exchangeRatesFetched)
if fes.backendServer != nil && fes.backendServer.GetStatsdClient() != nil {
if err = fes.backendServer.GetStatsdClient().Gauge("BLOCKCHAIN_LAST_TRADE_PRICE", blockchainDotComExchangeRate, []string{}, 1); err != nil {
glog.Errorf("GetBlockchainDotComExchangeRate: Error logging Last Trade Price of %f to datadog: %v", blockchainDotComExchangeRate, err)
glog.V(2).Infof("GetBlockchainDotComExchangeRate: Error logging Last Trade Price of %f to datadog: %v", blockchainDotComExchangeRate, err)
}
}
return blockchainDotComExchangeRate, nil
Expand Down
15 changes: 8 additions & 7 deletions routes/bitcoin_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/golang/glog"
"github.com/montanaflynn/stats"
"io/ioutil"
"net/http"
"strconv"

"github.com/golang/glog"
"github.com/montanaflynn/stats"
)

type CoinbaseResponse struct {
Expand Down Expand Up @@ -206,7 +207,7 @@ func GetUSDToBTCPrice() (float64, error) {
amount, err := getCoinbasePrice()
if err != nil {
// The amount will be zero in this case, which is fine
glog.Errorf("Error fetching Coinbase price: %v", err)
glog.V(2).Infof("Error fetching Coinbase price: %v", err)
}

if amount != 0 {
Expand All @@ -217,7 +218,7 @@ func GetUSDToBTCPrice() (float64, error) {
amount, err := getCoingeckoPrice()
if err != nil {
// The amount will be zero in this case, which is fine
glog.Errorf("Error fetching Coingecko price: %v", err)
glog.V(2).Infof("Error fetching Coingecko price: %v", err)
}

if amount != 0 {
Expand All @@ -228,7 +229,7 @@ func GetUSDToBTCPrice() (float64, error) {
amount, err := getBlockchainDotcomPrice()
if err != nil {
// The amount will be zero in this case, which is fine
glog.Errorf("Error fetching blockchain.com price: %v", err)
glog.V(2).Infof("Error fetching blockchain.com price: %v", err)
}

if amount != 0 {
Expand All @@ -239,7 +240,7 @@ func GetUSDToBTCPrice() (float64, error) {
amount, err := getGeminiPrice()
if err != nil {
// The amount will be zero in this case, which is fine
glog.Errorf("Error fetching Gemini price: %v", err)
glog.V(2).Infof("Error fetching Gemini price: %v", err)
}

if amount != 0 {
Expand All @@ -250,7 +251,7 @@ func GetUSDToBTCPrice() (float64, error) {
amount, err := getKrakenPrice()
if err != nil {
// The amount will be zero in this case, which is fine
glog.Errorf("Error fetching Kraken price: %v", err)
glog.V(2).Infof("Error fetching Kraken price: %v", err)
}

if amount != 0 {
Expand Down

0 comments on commit e0897e9

Please sign in to comment.