-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bacb21e
commit fba8130
Showing
18 changed files
with
270 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package context | ||
|
||
import ( | ||
"encoding/base64" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
func (c *Context) RemovePeer(key string) error { | ||
c.Log().Info("Removing peer from service", "key", key) | ||
|
||
data, err := base64.StdEncoding.DecodeString(key) | ||
if err != nil { | ||
c.Log().Error("Failed to decode the key", "error", err) | ||
return err | ||
} | ||
|
||
if err := c.Service().RemovePeer(data); err != nil { | ||
c.Log().Error("Failed to remove the peer from service", "error", err) | ||
return err | ||
} | ||
|
||
c.Log().Info("Removed peer from service...") | ||
return nil | ||
} | ||
|
||
func (c *Context) RemoveSession(key string, address sdk.AccAddress) error { | ||
c.Log().Info("Removing session from list", "key", key, "address", address) | ||
|
||
c.Sessions().DeleteByKey(key) | ||
c.Sessions().DeleteByAddress(address) | ||
|
||
c.Log().Info("Removed session from list...") | ||
return nil | ||
} | ||
|
||
func (c *Context) RemovePeerAndSession(key string, address sdk.AccAddress) error { | ||
if err := c.RemovePeer(key); err != nil { | ||
return err | ||
} | ||
if err := c.RemoveSession(key, address); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package context | ||
|
||
import ( | ||
"time" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
hubtypes "github.com/sentinel-official/hub/types" | ||
nodetypes "github.com/sentinel-official/hub/x/node/types" | ||
sessiontypes "github.com/sentinel-official/hub/x/session/types" | ||
|
||
"github.com/sentinel-official/dvpn-node/types" | ||
) | ||
|
||
func (c *Context) RegisterNode() error { | ||
c.Log().Info("Registering node...") | ||
|
||
_, err := c.Client().BroadcastTx( | ||
nodetypes.NewMsgRegisterRequest( | ||
c.Operator(), | ||
c.Provider(), | ||
c.Price(), | ||
c.RemoteURL(), | ||
), | ||
) | ||
if err != nil { | ||
c.Log().Error("Failed to register node", "error", err) | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *Context) UpdateNodeInfo() error { | ||
c.Log().Info("Updating node info...") | ||
|
||
_, err := c.Client().BroadcastTx( | ||
nodetypes.NewMsgUpdateRequest( | ||
c.Address(), | ||
c.Provider(), | ||
c.Price(), | ||
c.RemoteURL(), | ||
), | ||
) | ||
if err != nil { | ||
c.Log().Error("Failed to update node info", "error", err) | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *Context) UpdateNodeStatus() error { | ||
c.Log().Info("Updating node status...") | ||
|
||
_, err := c.Client().BroadcastTx( | ||
nodetypes.NewMsgSetStatusRequest( | ||
c.Address(), | ||
hubtypes.StatusActive, | ||
), | ||
) | ||
if err != nil { | ||
c.Log().Error("Failed to update node status", "error", err) | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *Context) UpdateSessions(items ...types.Session) error { | ||
c.Log().Info("Updating sessions...") | ||
|
||
var messages []sdk.Msg | ||
for _, item := range items { | ||
messages = append(messages, | ||
sessiontypes.NewMsgUpdateRequest( | ||
c.Address(), | ||
sessiontypes.Proof{ | ||
Id: item.ID, | ||
Duration: time.Since(item.ConnectedAt), | ||
Bandwidth: hubtypes.NewBandwidthFromInt64(item.Download, item.Upload), | ||
}, | ||
nil, | ||
), | ||
) | ||
} | ||
|
||
_, err := c.Client().BroadcastTx( | ||
messages..., | ||
) | ||
if err != nil { | ||
c.Log().Error("Failed to update sessions", "error", err) | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.