Commit c06463db authored by suyanlong's avatar suyanlong

Add route method and Fixed appchain process logic bug

parent a662d619
Pipeline #8056 canceled with stages
...@@ -3,6 +3,8 @@ package appchain ...@@ -3,6 +3,8 @@ package appchain
import ( import (
"errors" "errors"
"github.com/link33/sidecar/internal/repo"
"github.com/link33/sidecar/internal/router"
"github.com/link33/sidecar/model/pb" "github.com/link33/sidecar/model/pb"
) )
...@@ -49,11 +51,11 @@ func (a *appChain) Send(msg *pb.Message) (*pb.Message, error) { ...@@ -49,11 +51,11 @@ func (a *appChain) Send(msg *pb.Message) (*pb.Message, error) {
//TODO 默认路由 //TODO 默认路由
ix := pb.IBTPX{ ix := pb.IBTPX{
Ibtp: ibtp, Ibtp: ibtp,
Mode: "", Mode: repo.DirectMode,
RouteSign: nil, RouteSign: []string{},
RouteMethod: "", RouteMethod: router.Single,
RouteMethodArg: nil, RouteMethodArg: []string{},
IsValid: false, IsValid: false, // TODO
} }
d, err := ix.Marshal() d, err := ix.Marshal()
if err != nil { if err != nil {
......
package router
var (
Single = "single"
Multicast = "multicast"
Broadcast = "broadcast"
Official = "official"
Random = "random"
)
...@@ -40,10 +40,11 @@ func NewRouter(privateKey crypto.PrivateKey, logger logrus.FieldLogger) Router { ...@@ -40,10 +40,11 @@ func NewRouter(privateKey crypto.PrivateKey, logger logrus.FieldLogger) Router {
} }
func (r *router) Start() error { func (r *router) Start() error {
r.methodMap["single"] = r.Single r.methodMap[Single] = r.Single
r.methodMap["multicast"] = r.Multicast r.methodMap[Multicast] = r.Multicast
r.methodMap["broadcast"] = r.Broadcast r.methodMap[Broadcast] = r.Broadcast
r.methodMap["official"] = r.Official r.methodMap[Official] = r.Official
r.methodMap[Random] = r.Random
return nil return nil
} }
...@@ -266,6 +267,10 @@ func (r *router) Broadcast([]string) []port.Port { ...@@ -266,6 +267,10 @@ func (r *router) Broadcast([]string) []port.Port {
return r.portMap.AllRouterPort() return r.portMap.AllRouterPort()
} }
func (r *router) Random([]string) []port.Port {
return []port.Port{r.portMap.RandRouterPort()}
}
func (r *router) Official(tags []string) []port.Port { func (r *router) Official(tags []string) []port.Port {
var ps []port.Port var ps []port.Port
for _, tag := range tags { for _, tag := range tags {
...@@ -304,4 +309,5 @@ type RouteMethod interface { ...@@ -304,4 +309,5 @@ type RouteMethod interface {
Multicast([]string) []port.Port Multicast([]string) []port.Port
Broadcast([]string) []port.Port Broadcast([]string) []port.Port
Official([]string) []port.Port Official([]string) []port.Port
Random([]string) []port.Port
} }
...@@ -11,9 +11,9 @@ type Kernel interface { ...@@ -11,9 +11,9 @@ type Kernel interface {
Exited() bool Exited() bool
} }
// Client defines the interface that interacts with appchain 与 appchain交互。 // Client defines the interface that interacts with appchain
//go:generate mockgen -destination mock_client/mock_client.go -package mock_client -source interface.go //go:generate mockgen -destination mock_client/mock_client.go -package mock_client -source interface.go
type Client interface { // 业务实现委托接口。需要实现的那有些。 type Client interface { // 业务实现委托接口。
internal.Launcher internal.Launcher
Kernel Kernel
Bind(kern Kernel) Bind(kern Kernel)
......
...@@ -35,3 +35,9 @@ func Exist(path string) bool { ...@@ -35,3 +35,9 @@ func Exist(path string) bool {
return false return false
} }
//https://github.com/fatih/gomodifytags
//https://github.com/favadi/protoc-go-inject-tag
//https://github.com/0xAX/go-algorithms
//https://github.com/emirpasic/gods
//
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment