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
import (
"errors"
"github.com/link33/sidecar/internal/repo"
"github.com/link33/sidecar/internal/router"
"github.com/link33/sidecar/model/pb"
)
......@@ -49,11 +51,11 @@ func (a *appChain) Send(msg *pb.Message) (*pb.Message, error) {
//TODO 默认路由
ix := pb.IBTPX{
Ibtp: ibtp,
Mode: "",
RouteSign: nil,
RouteMethod: "",
RouteMethodArg: nil,
IsValid: false,
Mode: repo.DirectMode,
RouteSign: []string{},
RouteMethod: router.Single,
RouteMethodArg: []string{},
IsValid: false, // TODO
}
d, err := ix.Marshal()
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 {
}
func (r *router) Start() error {
r.methodMap["single"] = r.Single
r.methodMap["multicast"] = r.Multicast
r.methodMap["broadcast"] = r.Broadcast
r.methodMap["official"] = r.Official
r.methodMap[Single] = r.Single
r.methodMap[Multicast] = r.Multicast
r.methodMap[Broadcast] = r.Broadcast
r.methodMap[Official] = r.Official
r.methodMap[Random] = r.Random
return nil
}
......@@ -266,6 +267,10 @@ func (r *router) Broadcast([]string) []port.Port {
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 {
var ps []port.Port
for _, tag := range tags {
......@@ -304,4 +309,5 @@ type RouteMethod interface {
Multicast([]string) []port.Port
Broadcast([]string) []port.Port
Official([]string) []port.Port
Random([]string) []port.Port
}
......@@ -11,9 +11,9 @@ type Kernel interface {
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
type Client interface { // 业务实现委托接口。需要实现的那有些。
type Client interface { // 业务实现委托接口。
internal.Launcher
Kernel
Bind(kern Kernel)
......
......@@ -35,3 +35,9 @@ func Exist(path string) bool {
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