Skip to content

Commit

Permalink
Fix query and incorrect host IP issues
Browse files Browse the repository at this point in the history
  • Loading branch information
bsrinivas8687 committed Jan 13, 2021
1 parent 18990f2 commit f44e4bd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN apk add git gcc linux-headers make musl-dev && \
make install --jobs=$(nproc)

RUN cd /root/ && \
apk add autoconf automake g++ git libtool make unbound-dev && \
apk add autoconf automake file g++ git libtool make unbound-dev && \
git clone https://github.com/handshake-org/hnsd.git --branch=v1.0.0 --depth=1 && \
cd /root/hnsd/ && \
bash autogen.sh && sh configure && make --jobs=$(nproc)
Expand Down
21 changes: 11 additions & 10 deletions lite/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ import (
"github.com/sentinel-official/hub/x/vpn"
)

func (c *Client) Query(path string, params, result interface{}) error {
func (c *Client) Query(path string, params, result interface{}) (bool, error) {
bytes, err := c.ctx.Codec.MarshalJSON(params)
if err != nil {
return err
return false, err
}

res, _, err := c.ctx.QueryWithData(path, bytes)
if err != nil {
return err
return false, err
}
if res == nil {
return nil
return false, nil
}

return c.ctx.Codec.UnmarshalJSON(res, result)
return true, c.ctx.Codec.UnmarshalJSON(res, result)
}

func (c *Client) QueryAccount(address sdk.AccAddress) (exported.Account, error) {
Expand All @@ -36,7 +36,7 @@ func (c *Client) QueryAccount(address sdk.AccAddress) (exported.Account, error)
path = fmt.Sprintf("custom/%s/%s", auth.QuerierRoute, auth.QueryAccount)
)

if err := c.Query(path, auth.NewQueryAccountParams(address), &result); err != nil {
if ok, err := c.Query(path, auth.NewQueryAccountParams(address), &result); !ok {
return nil, err
}

Expand All @@ -49,7 +49,7 @@ func (c *Client) QueryNode(address hub.NodeAddress) (*node.Node, error) {
path = fmt.Sprintf("custom/%s/%s/%s", vpn.StoreKey, node.QuerierRoute, node.QueryNode)
)

if err := c.Query(path, node.NewQueryNodeParams(address), &result); err != nil {
if ok, err := c.Query(path, node.NewQueryNodeParams(address), &result); !ok {
return nil, err
}

Expand All @@ -62,7 +62,7 @@ func (c *Client) QuerySubscription(id uint64) (*subscription.Subscription, error
path = fmt.Sprintf("custom/%s/%s/%s", vpn.StoreKey, subscription.QuerierRoute, subscription.QuerySubscription)
)

if err := c.Query(path, subscription.NewQuerySubscriptionParams(id), &result); err != nil {
if ok, err := c.Query(path, subscription.NewQuerySubscriptionParams(id), &result); !ok {
return nil, err
}

Expand All @@ -75,15 +75,16 @@ func (c *Client) QueryQuota(id uint64, address sdk.AccAddress) (*subscription.Qu
path = fmt.Sprintf("custom/%s/%s/%s", vpn.StoreKey, subscription.QuerierRoute, subscription.QueryQuota)
)

if err := c.Query(path, subscription.NewQueryQuotaParams(id, address), &result); err != nil {
if ok, err := c.Query(path, subscription.NewQueryQuotaParams(id, address), &result); !ok {
return nil, err
}

return &result, nil
}

func (c *Client) HasNodeForPlan(id uint64, address hub.NodeAddress) (bool, error) {
res, _, err := c.ctx.QueryStore(plan.NodeForPlanKey(id, address), vpn.ModuleName)
res, _, err := c.ctx.QueryStore(plan.NodeForPlanKey(id, address),
fmt.Sprintf("%s/%s", vpn.ModuleName, plan.ModuleName))
if err != nil {
return false, err
}
Expand Down
2 changes: 1 addition & 1 deletion rest/session/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func HandlerAddSession(ctx *context.Context) http.HandlerFunc {
return
}

result = append(result, net.ParseIP(ctx.Location().IP)...)
result = append(result, net.ParseIP(ctx.Location().IP).To4()...)
result = append(result, ctx.Service().Info()...)
utils.WriteResultToResponse(w, http.StatusCreated, result)
}
Expand Down

0 comments on commit f44e4bd

Please sign in to comment.