Skip to content

Commit

Permalink
Cleaned up imports
Browse files Browse the repository at this point in the history
  • Loading branch information
vikulin committed Dec 20, 2023
1 parent 74bf1f5 commit 0d26847
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 34 deletions.
3 changes: 1 addition & 2 deletions src/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,8 @@ func (c *Core) ReadFrom(p []byte) (n int, from net.Addr, err error) {
case typeSessionTraffic:
// This is what we want to handle here
case typeSessionProto:
key := iwt.Domain(from.(iwt.Addr))
data := append([]byte(nil), bs[1:n]...)
c.proto.handleProto(nil, key, data)
c.proto.handleProto(nil, from.(iwt.Addr), data)
continue
default:
continue
Expand Down
17 changes: 8 additions & 9 deletions src/core/nodeinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"time"

"github.com/Arceliar/ironwood/types"
iwt "github.com/Arceliar/ironwood/types"
"github.com/Arceliar/phony"

//"github.com/RiV-chain/RiV-mesh/src/crypto"
Expand Down Expand Up @@ -103,42 +102,42 @@ func (m *nodeinfo) _setNodeInfo(given map[string]interface{}, privacy bool) erro
}
}

func (m *nodeinfo) sendReq(from phony.Actor, key iwt.Domain, callback func(nodeinfo json.RawMessage)) {
func (m *nodeinfo) sendReq(from phony.Actor, key types.Domain, callback func(nodeinfo json.RawMessage)) {
m.Act(from, func() {
m._sendReq(key, callback)
})
}

func (m *nodeinfo) _sendReq(domain iwt.Domain, callback func(nodeinfo json.RawMessage)) {
func (m *nodeinfo) _sendReq(domain types.Domain, callback func(nodeinfo json.RawMessage)) {
if callback != nil {
key := domain.Key
m._addCallback(key, callback)
}
_, _ = m.proto.core.PacketConn.WriteTo([]byte{typeSessionProto, typeProtoNodeInfoRequest}, iwt.Addr(domain))
_, _ = m.proto.core.PacketConn.WriteTo([]byte{typeSessionProto, typeProtoNodeInfoRequest}, types.Addr(domain))
}

func (m *nodeinfo) handleReq(from phony.Actor, key iwt.Domain) {
func (m *nodeinfo) handleReq(from phony.Actor, key types.Addr) {
m.Act(from, func() {
m._sendRes(key)
})
}

func (m *nodeinfo) handleRes(from phony.Actor, domain iwt.Domain, info json.RawMessage) {
func (m *nodeinfo) handleRes(from phony.Actor, domain types.Addr, info json.RawMessage) {
m.Act(from, func() {
key := domain.Key
m._callback(key, info)
})
}

func (m *nodeinfo) _sendRes(key iwt.Domain) {
func (m *nodeinfo) _sendRes(key types.Addr) {
bs := append([]byte{typeSessionProto, typeProtoNodeInfoResponse}, m._getNodeInfo()...)
_, _ = m.proto.core.PacketConn.WriteTo(bs, iwt.Addr(key))
_, _ = m.proto.core.PacketConn.WriteTo(bs, key)
}

// Admin socket stuff

type GetNodeInfoRequest struct {
Key iwt.Domain `json:"key"`
Key types.Domain `json:"key"`
}
type GetNodeInfoResponse map[string]json.RawMessage

Expand Down
43 changes: 20 additions & 23 deletions src/core/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"time"

"github.com/Arceliar/ironwood/types"
iwt "github.com/Arceliar/ironwood/types"
"github.com/Arceliar/phony"
//"github.com/RiV-chain/RiV-mesh/src/address"
)
Expand All @@ -28,8 +27,6 @@ type reqInfo struct {
timer *time.Timer // time.AfterFunc cleanup
}

type keyArray types.PublicKey

type protoHandler struct {
phony.Inbox

Expand All @@ -52,7 +49,7 @@ func (p *protoHandler) init(core *Core) {

// Common functions

func (p *protoHandler) handleProto(from phony.Actor, key iwt.Domain, bs []byte) {
func (p *protoHandler) handleProto(from phony.Actor, key types.Addr, bs []byte) {
if len(bs) == 0 {
return
}
Expand All @@ -67,13 +64,13 @@ func (p *protoHandler) handleProto(from phony.Actor, key iwt.Domain, bs []byte)
}
}

func (p *protoHandler) handleDebug(from phony.Actor, key iwt.Domain, bs []byte) {
func (p *protoHandler) handleDebug(from phony.Actor, key types.Addr, bs []byte) {
p.Act(from, func() {
p._handleDebug(key, bs)
})
}

func (p *protoHandler) _handleDebug(domain iwt.Domain, bs []byte) {
func (p *protoHandler) _handleDebug(domain types.Addr, bs []byte) {
if len(bs) == 0 {
return
}
Expand All @@ -95,14 +92,14 @@ func (p *protoHandler) _handleDebug(domain iwt.Domain, bs []byte) {
}
}

func (p *protoHandler) _sendDebug(key iwt.Domain, dType uint8, data []byte) {
func (p *protoHandler) _sendDebug(key types.Addr, dType uint8, data []byte) {
bs := append([]byte{typeSessionProto, typeProtoDebug, dType}, data...)
_, _ = p.core.PacketConn.WriteTo(bs, iwt.Addr(key))
_, _ = p.core.PacketConn.WriteTo(bs, key)
}

// Get self

func (p *protoHandler) sendGetSelfRequest(domain iwt.Domain, callback func([]byte)) {
func (p *protoHandler) sendGetSelfRequest(domain types.Addr, callback func([]byte)) {
p.Act(nil, func() {
key := domain.Key
if info := p.selfRequests[key]; info != nil {
Expand All @@ -123,7 +120,7 @@ func (p *protoHandler) sendGetSelfRequest(domain iwt.Domain, callback func([]byt
})
}

func (p *protoHandler) _handleGetSelfRequest(key iwt.Domain) {
func (p *protoHandler) _handleGetSelfRequest(key types.Addr) {
self := p.core.GetSelf()
res := map[string]string{
"key": hex.EncodeToString(self.Domain.Key.ToSlice()),
Expand All @@ -138,7 +135,7 @@ func (p *protoHandler) _handleGetSelfRequest(key iwt.Domain) {
p._sendDebug(key, typeDebugGetSelfResponse, bs)
}

func (p *protoHandler) _handleGetSelfResponse(domain iwt.Domain, bs []byte) {
func (p *protoHandler) _handleGetSelfResponse(domain types.Addr, bs []byte) {

key := domain.Key
if info := p.selfRequests[key]; info != nil {
Expand All @@ -150,7 +147,7 @@ func (p *protoHandler) _handleGetSelfResponse(domain iwt.Domain, bs []byte) {

// Get peers

func (p *protoHandler) sendGetPeersRequest(domain iwt.Domain, callback func([]byte)) {
func (p *protoHandler) sendGetPeersRequest(domain types.Addr, callback func([]byte)) {
p.Act(nil, func() {
key := domain.Key
if info := p.peersRequests[key]; info != nil {
Expand All @@ -171,7 +168,7 @@ func (p *protoHandler) sendGetPeersRequest(domain iwt.Domain, callback func([]by
})
}

func (p *protoHandler) _handleGetPeersRequest(domain iwt.Domain) {
func (p *protoHandler) _handleGetPeersRequest(domain types.Addr) {
peers := p.core.GetPeers()
var bs []byte
for _, pinfo := range peers {
Expand All @@ -185,7 +182,7 @@ func (p *protoHandler) _handleGetPeersRequest(domain iwt.Domain) {
p._sendDebug(domain, typeDebugGetPeersResponse, bs)
}

func (p *protoHandler) _handleGetPeersResponse(domain iwt.Domain, bs []byte) {
func (p *protoHandler) _handleGetPeersResponse(domain types.Addr, bs []byte) {
key := domain.Key
if info := p.peersRequests[key]; info != nil {
info.timer.Stop()
Expand All @@ -196,7 +193,7 @@ func (p *protoHandler) _handleGetPeersResponse(domain iwt.Domain, bs []byte) {

// Get DHT

func (p *protoHandler) sendGetDHTRequest(domain iwt.Domain, callback func([]byte)) {
func (p *protoHandler) sendGetDHTRequest(domain types.Addr, callback func([]byte)) {
p.Act(nil, func() {
key := domain.Key
if info := p.dhtRequests[key]; info != nil {
Expand All @@ -217,7 +214,7 @@ func (p *protoHandler) sendGetDHTRequest(domain iwt.Domain, callback func([]byte
})
}

func (p *protoHandler) _handleGetTreeRequest(domain iwt.Domain) {
func (p *protoHandler) _handleGetTreeRequest(domain types.Addr) {
dinfos := p.core.GetTree()
var bs []byte
for _, dinfo := range dinfos {
Expand All @@ -231,7 +228,7 @@ func (p *protoHandler) _handleGetTreeRequest(domain iwt.Domain) {
p._sendDebug(domain, typeDebugGetTreeResponse, bs)
}

func (p *protoHandler) _handleGetTreeResponse(domain iwt.Domain, bs []byte) {
func (p *protoHandler) _handleGetTreeResponse(domain types.Addr, bs []byte) {
key := domain.Key
if info := p.dhtRequests[key]; info != nil {
info.timer.Stop()
Expand All @@ -243,7 +240,7 @@ func (p *protoHandler) _handleGetTreeResponse(domain iwt.Domain, bs []byte) {
// Admin socket stuff for "Get self"

type DebugGetSelfRequest struct {
Key iwt.Domain `json:"key"`
Key types.Domain `json:"key"`
}

type DebugGetSelfResponse map[string]interface{}
Expand All @@ -254,7 +251,7 @@ func (p *protoHandler) getSelfHandler(in json.RawMessage) (interface{}, error) {
return nil, err
}
ch := make(chan []byte, 1)
p.sendGetSelfRequest(req.Key, func(info []byte) {
p.sendGetSelfRequest(types.Addr(req.Key), func(info []byte) {
ch <- info
})
timer := time.NewTimer(6 * time.Second)
Expand All @@ -276,7 +273,7 @@ func (p *protoHandler) getSelfHandler(in json.RawMessage) (interface{}, error) {
// Admin socket stuff for "Get peers"

type DebugGetPeersRequest struct {
Key iwt.Domain `json:"key"`
Key types.Domain `json:"key"`
}

type DebugGetPeersResponse map[string]interface{}
Expand All @@ -288,7 +285,7 @@ func (p *protoHandler) getPeersHandler(in json.RawMessage) (interface{}, error)
}
key := req.Key.Key

Check failure on line 286 in src/core/proto.go

View workflow job for this annotation

GitHub Actions / Lint

SA4006: this value of `key` is never used (staticcheck)

Check failure on line 286 in src/core/proto.go

View workflow job for this annotation

GitHub Actions / Lint

SA4006: this value of `key` is never used (staticcheck)
ch := make(chan []byte, 1)
p.sendGetPeersRequest(req.Key, func(info []byte) {
p.sendGetPeersRequest(types.Addr(req.Key), func(info []byte) {
ch <- info
})
timer := time.NewTimer(6 * time.Second)
Expand Down Expand Up @@ -320,7 +317,7 @@ func (p *protoHandler) getPeersHandler(in json.RawMessage) (interface{}, error)
// Admin socket stuff for "Get DHT"

type DebugGetDHTRequest struct {
Key iwt.Domain `json:"key"`
Key types.Domain `json:"key"`
}

type DebugGetDHTResponse map[string]interface{}
Expand All @@ -332,7 +329,7 @@ func (p *protoHandler) getDHTHandler(in json.RawMessage) (interface{}, error) {
}
key := req.Key.Key

Check failure on line 330 in src/core/proto.go

View workflow job for this annotation

GitHub Actions / Lint

SA4006: this value of `key` is never used (staticcheck)

Check failure on line 330 in src/core/proto.go

View workflow job for this annotation

GitHub Actions / Lint

SA4006: this value of `key` is never used (staticcheck)
ch := make(chan []byte, 1)
p.sendGetDHTRequest(req.Key, func(info []byte) {
p.sendGetDHTRequest(types.Addr(req.Key), func(info []byte) {
ch <- info
})
timer := time.NewTimer(6 * time.Second)
Expand Down

0 comments on commit 0d26847

Please sign in to comment.