Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Rename RouteID -> RouteId
Browse files Browse the repository at this point in the history
  • Loading branch information
bzEq committed Apr 7, 2024
1 parent 000eb18 commit bdc4250
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
12 changes: 6 additions & 6 deletions core/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"github.com/bzEq/bx/core/iovec"
)

type RouteID uint64
type RouteId uint64

type Codec interface {
Encode(RouteID, *iovec.IoVec) error
Decode(*iovec.IoVec) (RouteID, error)
Encode(RouteId, *iovec.IoVec) error
Decode(*iovec.IoVec) (RouteId, error)
}

type RouteInfo struct {
Expand All @@ -24,10 +24,10 @@ type RouteInfo struct {
type SimpleRouter struct {
P *SyncPort
C Codec
routes Map[RouteID, *RouteInfo]
routes Map[RouteId, *RouteInfo]
}

func (self *SimpleRouter) route(id RouteID, ri *RouteInfo) {
func (self *SimpleRouter) route(id RouteId, ri *RouteInfo) {
for {
var b iovec.IoVec
err := ri.P.Unpack(&b)
Expand All @@ -47,7 +47,7 @@ func (self *SimpleRouter) route(id RouteID, ri *RouteInfo) {
}
}

func (self *SimpleRouter) NewRoute(id RouteID, P *SyncPort) (*RouteInfo, error) {
func (self *SimpleRouter) NewRoute(id RouteId, P *SyncPort) (*RouteInfo, error) {
ri := &RouteInfo{P: P, Err: make(chan error)}
if v, in := self.routes.LoadOrStore(id, ri); in {
return v, fmt.Errorf("Route #%d already exists", id)
Expand Down
20 changes: 10 additions & 10 deletions intrinsic/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (self *ClientContext) dialUDP(network, addr string) (net.Conn, error) {
id := disp.NewEntry(addr)
defer disp.DeleteEntry(id)
cp := core.NewSyncPortWithTimeout(c, nil, core.DEFAULT_UDP_TIMEOUT)
r, err := router.NewRoute(core.RouteID(id), cp)
r, err := router.NewRoute(core.RouteId(id), cp)
if err != nil {
log.Println(err)
return
Expand Down Expand Up @@ -165,24 +165,24 @@ func (self *ClientContext) getOrCreateRouter() (*core.SimpleRouter, error) {
}

type UDPDispatcher struct {
t core.Map[core.RouteID, string]
t core.Map[core.RouteId, string]
c uint64
}

func (self *UDPDispatcher) NewEntry(addr string) core.RouteID {
id := core.RouteID(atomic.AddUint64(&self.c, 1))
func (self *UDPDispatcher) NewEntry(addr string) core.RouteId {
id := core.RouteId(atomic.AddUint64(&self.c, 1))
self.t.Store(id, addr)
return id
}

func (self *UDPDispatcher) DeleteEntry(id core.RouteID) {
func (self *UDPDispatcher) DeleteEntry(id core.RouteId) {
self.t.Delete(id)
}

func (self *UDPDispatcher) Encode(id core.RouteID, data *iovec.IoVec) error {
func (self *UDPDispatcher) Encode(id core.RouteId, data *iovec.IoVec) error {
raddr, in := self.t.Load(id)
if !in {
return fmt.Errorf("Remote address of RouteID #%d doesn't exist", id)
return fmt.Errorf("Remote address of RouteId #%d doesn't exist", id)
}
msg := UDPMessage{Id: uint64(id), Addr: raddr, Data: data.Consume()}
var buf bytes.Buffer
Expand All @@ -194,12 +194,12 @@ func (self *UDPDispatcher) Encode(id core.RouteID, data *iovec.IoVec) error {
return nil
}

func (self *UDPDispatcher) Decode(data *iovec.IoVec) (core.RouteID, error) {
func (self *UDPDispatcher) Decode(data *iovec.IoVec) (core.RouteId, error) {
dec := gob.NewDecoder(bytes.NewBuffer(data.Consume()))
var msg UDPMessage
if err := dec.Decode(&msg); err != nil {
return core.RouteID(^uint64(0)), err
return core.RouteId(^uint64(0)), err
}
data.Take(msg.Data)
return core.RouteID(msg.Id), nil
return core.RouteId(msg.Id), nil
}

0 comments on commit bdc4250

Please sign in to comment.