Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sidecar
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
sidecar
Commits
0cdf9a37
Commit
0cdf9a37
authored
Oct 22, 2021
by
suyanlong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
😘
Add rule Validation Engine function
parent
f7fdb365
Pipeline
#8156
failed with stages
Changes
10
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
194 additions
and
7 deletions
+194
-7
server.go
api/server.go
+5
-2
go.mod
go.mod
+10
-2
go.sum
go.sum
+22
-0
sidecar.go
internal/app/sidecar.go
+5
-1
checker.go
internal/checker/checker.go
+40
-1
loggers.go
internal/loggers/loggers.go
+3
-1
config.go
internal/repo/config.go
+1
-0
code_ledger.go
internal/rulemgr/code_ledger.go
+24
-0
handle.go
internal/rulemgr/handle.go
+40
-0
rule_mgr.go
internal/rulemgr/rule_mgr.go
+44
-0
No files found.
api/server.go
View file @
0cdf9a37
...
...
@@ -15,6 +15,7 @@ import (
"github.com/link33/sidecar/cmd/sidecar/client"
"github.com/link33/sidecar/internal/peermgr"
"github.com/link33/sidecar/internal/repo"
"github.com/link33/sidecar/internal/rulemgr"
"github.com/link33/sidecar/model/pb"
)
...
...
@@ -25,13 +26,14 @@ type Server struct {
ctx
context
.
Context
cancel
context
.
CancelFunc
peerMgr
peermgr
.
PeerManager
rule
*
rulemgr
.
RuleMgr
}
type
response
struct
{
Data
[]
byte
`json:"data"`
}
func
NewServer
(
config
*
repo
.
Config
,
peerMgr
peermgr
.
PeerManager
,
logger
logrus
.
FieldLogger
)
*
Server
{
func
NewServer
(
config
*
repo
.
Config
,
peerMgr
peermgr
.
PeerManager
,
rule
*
rulemgr
.
RuleMgr
,
logger
logrus
.
FieldLogger
)
*
Server
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
gin
.
SetMode
(
gin
.
ReleaseMode
)
router
:=
gin
.
New
()
...
...
@@ -42,6 +44,7 @@ func NewServer(config *repo.Config, peerMgr peermgr.PeerManager, logger logrus.F
ctx
:
ctx
,
cancel
:
cancel
,
peerMgr
:
peerMgr
,
rule
:
rule
,
}
}
...
...
@@ -63,7 +66,7 @@ func (g *Server) Start() error {
}()
<-
g
.
ctx
.
Done
()
}()
return
nil
return
g
.
peerMgr
.
RegisterMsgHandler
(
pb
.
Message_RULE_DEPLOY
,
g
.
rule
.
HandleRule
)
}
func
(
g
*
Server
)
Stop
()
error
{
...
...
go.mod
View file @
0cdf9a37
...
...
@@ -6,6 +6,7 @@ require (
github.com/Rican7/retry v0.1.0
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de
github.com/bits-and-blooms/bitset v1.2.1
github.com/bits-and-blooms/bloom/v3 v3.1.0
github.com/btcsuite/btcd v0.21.0-beta
github.com/bxcodec/faker/v3 v3.6.0
github.com/cbergoon/merkletree v0.2.0
...
...
@@ -37,6 +38,7 @@ require (
github.com/juju/errors v0.0.0-20210818161939-5560c4c073ff
github.com/lestrrat-go/file-rotatelogs v2.2.0+incompatible
github.com/libp2p/go-libp2p-core v0.6.1
github.com/magiconair/properties v1.8.1
github.com/meshplus/bitxhub-core v1.3.1-0.20210524071255-789fd9ab501c
github.com/meshplus/bitxhub-kit v1.2.1-0.20210524063043-9afae78ac098
github.com/meshplus/bitxid v0.0.0-20210412025850-e0eaf0f9063a
...
...
@@ -60,7 +62,7 @@ require (
)
require (
github.com/
bits-and-blooms/bloom/v3 v3.1.0
// indirect
github.com/
Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible
// indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
...
...
@@ -80,6 +82,9 @@ require (
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb // indirect
github.com/huin/goupnp v1.0.0 // indirect
github.com/hyperledger/fabric v2.0.1+incompatible // indirect
github.com/hyperledger/fabric-amcl v0.0.0-20200424173818-327c9e2cf77a // indirect
github.com/hyperledger/fabric-protos-go v0.0.0-20200330074707-cfe579e86986 // indirect
github.com/ipfs/go-datastore v0.4.4 // indirect
github.com/ipfs/go-ipfs-util v0.0.1 // indirect
github.com/ipfs/go-ipns v0.0.2 // indirect
...
...
@@ -132,9 +137,10 @@ require (
github.com/libp2p/go-ws-transport v0.3.1 // indirect
github.com/libp2p/go-yamux v1.3.6 // indirect
github.com/looplab/fsm v0.2.0 // indirect
github.com/magiconair/properties v1.8.1 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/meshplus/bitxhub-model v1.2.1-0.20210524063354-5d48e2fee178 // indirect
github.com/miekg/pkcs11 v1.0.3 // indirect
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 // indirect
github.com/minio/sha256-simd v0.1.1 // indirect
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
...
...
@@ -164,11 +170,13 @@ require (
github.com/spf13/jwalterweatherman v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/sykesm/zap-logfmt v0.0.3 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210305035536-64b5b1c73954 // indirect
github.com/tidwall/match v1.0.3 // indirect
github.com/tidwall/pretty v1.0.2 // indirect
github.com/ugorji/go/codec v1.1.7 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/wasmerio/go-ext-wasm v0.3.1 // indirect
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect
github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7 // indirect
go.opencensus.io v0.22.3 // indirect
...
...
go.sum
View file @
0cdf9a37
...
...
@@ -16,6 +16,7 @@ github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOv
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible h1:1G1pk05UrOh0NlF1oeaaix1x8XzrfjIDK47TY0Zehcw=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/Kubuxu/go-os-helper v0.0.1/go.mod h1:N8B+I7vPCT80IcP58r50u4+gEEcsZETFUpAzWW2ep1Y=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
...
...
@@ -23,6 +24,7 @@ github.com/OpenPeeDeeP/depguard v1.0.1/go.mod h1:xsIw86fROiiwelg+jB2uM9PiKihMMmU
github.com/Rican7/retry v0.1.0 h1:FqK94z34ly8Baa6K+G8Mmza9rYWTKOJk+yckIBB5qVk=
github.com/Rican7/retry v0.1.0/go.mod h1:FgOROf8P5bebcC1DS0PdOQiqGUridaZvikzUmkFW6gg=
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
github.com/Shopify/sarama v1.27.0 h1:tqo2zmyzPf1+gwTTwhI6W+EXDw4PVSczynpHKFtVAmo=
github.com/Shopify/sarama v1.27.0/go.mod h1:aCdj6ymI8uyPEux1JJ9gcaDT6cinjGhNCAhs54taSUo=
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
...
...
@@ -130,8 +132,11 @@ github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
github.com/eapache/go-resiliency v1.2.0 h1:v7g92e/KSN71Rq7vSThKaWIq68fL4YHvWyiUKorFR1Q=
github.com/eapache/go-resiliency v1.2.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 h1:YEetp8/yCZMuEPMUDHG0CW/brkkEp8mzqk2+ODEitlw=
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc=
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
github.com/elliotchance/orderedmap v1.4.0 h1:wZtfeEONCbx6in1CZyE6bELEt/vFayMvsxqI5SgsR+A=
...
...
@@ -324,8 +329,10 @@ github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerX
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.2 h1:cfejS+Tpcp13yd5nYHWDI6qVCny6wyX2Mt5SGur2IGE=
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pBJ3TkI=
github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
...
...
@@ -351,8 +358,11 @@ github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmK
github.com/huin/goupnp v1.0.0 h1:wg75sLpL6DZqwHQN6E1Cfk6mtfzS45z8OV+ic+DtHRo=
github.com/huin/goupnp v1.0.0/go.mod h1:n9v9KO1tAxYH82qOn+UTIFQDmx5n1Zxd/ClZDMX7Bnc=
github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o=
github.com/hyperledger/fabric v2.0.1+incompatible h1:7W+yG0gLKTC7NLcWPT3vfpnaseztPpH9wXGfAW7yvBs=
github.com/hyperledger/fabric v2.0.1+incompatible/go.mod h1:tGFAOCT696D3rG0Vofd2dyWYLySHlh0aQjf7Q1HAju0=
github.com/hyperledger/fabric-amcl v0.0.0-20200424173818-327c9e2cf77a h1:JAKZdGuUIjVmES0X31YUD7UqMR2rz/kxLluJuGvsXPk=
github.com/hyperledger/fabric-amcl v0.0.0-20200424173818-327c9e2cf77a/go.mod h1:X+DIyUsaTmalOpmpQfIvFZjKHQedrURQ5t4YqquX7lE=
github.com/hyperledger/fabric-protos-go v0.0.0-20200330074707-cfe579e86986 h1:g9tgYXQPZcxRryp2/rutvfSCiiJzHNoyX7JaoXeGkZ8=
github.com/hyperledger/fabric-protos-go v0.0.0-20200330074707-cfe579e86986/go.mod h1:xVYTjK4DtZRBxZ2D9aE4y6AbLaPwue2o/criQyQbVD0=
github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
...
...
@@ -410,6 +420,7 @@ github.com/jbenet/goprocess v0.0.0-20160826012719-b497e2f366b8/go.mod h1:Ly/wlsj
github.com/jbenet/goprocess v0.1.3/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZlqdZVfqY4=
github.com/jbenet/goprocess v0.1.4 h1:DRGOFReOMqqDNXwW70QkacFW0YN9QnwLV0Vqk+3oU0o=
github.com/jbenet/goprocess v0.1.4/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZlqdZVfqY4=
github.com/jcmturner/gofork v1.0.0 h1:J7uCkflzTEhUZ64xqKnkDxq3kzc96ajM1Gli5ktUem8=
github.com/jcmturner/gofork v1.0.0/go.mod h1:MK8+TM0La+2rjBD4jE12Kj1pCCxK7d2LK/UM3ncEo0o=
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 h1:IPJ3dvxmJ4uczJe5YQdrYB16oTJlGSC/OyZDqUk9xX4=
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869/go.mod h1:cJ6Cj7dQo+O6GJNiMx+Pa94qKj+TG8ONdKHgMNIyyag=
...
...
@@ -454,6 +465,7 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
github.com/klauspost/compress v1.4.0/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.10.10 h1:a/y8CglcM7gLGYmlbP/stPE5sR3hbhFRUjCBfd/0B3I=
github.com/klauspost/compress v1.10.10/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
...
...
@@ -666,6 +678,7 @@ github.com/meshplus/bitxhub-kit v1.2.1-0.20210524063043-9afae78ac098 h1:/E1isgGc
github.com/meshplus/bitxhub-kit v1.2.1-0.20210524063043-9afae78ac098/go.mod h1:wrEdhHp1tktzdwcWb4bOxYsVc+KkcrYL18IYWYeumPQ=
github.com/meshplus/bitxhub-model v1.0.0-rc3/go.mod h1:ZCctQIYTlE3vJ8Lhkrgs9bWwNA+Dw4JzojOSIzLVU6E=
github.com/meshplus/bitxhub-model v1.1.1/go.mod h1:lUl9vPZXM9tP+B0ABRW/2eOW/6KCmjFTdoiTj5Vut/A=
github.com/meshplus/bitxhub-model v1.2.1-0.20210524063354-5d48e2fee178 h1:z8KGkI7DBGX9c4dUZNMT7kfBvUqZNqGNuI7uyKLZ5Tc=
github.com/meshplus/bitxhub-model v1.2.1-0.20210524063354-5d48e2fee178/go.mod h1:vwJ+sHPUyA2JELmUUDBol+7zA+7GcqutxzqXjsN0QLA=
github.com/meshplus/bitxid v0.0.0-20210412025850-e0eaf0f9063a h1:c4ESPDa60Jd4zfzZIGGTyzhfaVM3vKN+xV2G9BwIDGQ=
github.com/meshplus/bitxid v0.0.0-20210412025850-e0eaf0f9063a/go.mod h1:vAldSRfDe2Qo7exsSTbchVmZWXPY7fhWQrRw18QJHho=
...
...
@@ -674,6 +687,7 @@ github.com/meshplus/go-lightp2p v0.0.0-20200817105923-6b3aee40fa54/go.mod h1:G89
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/miekg/dns v1.1.12/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/miekg/dns v1.1.28/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM=
github.com/miekg/pkcs11 v1.0.3 h1:iMwmD7I5225wv84WxIG/bmxz9AXjWvTWIbM/TYHvWtw=
github.com/miekg/pkcs11 v1.0.3/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs=
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g=
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ=
...
...
@@ -811,6 +825,7 @@ github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/9
github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac=
github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc=
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pierrec/lz4 v2.5.2+incompatible h1:WCjObylUIOlKy/+7Abdn34TLIkXiA4UWUMhxq9m9ZXI=
github.com/pierrec/lz4 v2.5.2+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
...
...
@@ -844,6 +859,7 @@ github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40T
github.com/prometheus/tsdb v0.10.0/go.mod h1:oi49uRhEe9dPUTlS3JRZOwJuVi6tmh10QSgwXEyGCt4=
github.com/quasilyte/go-consistent v0.0.0-20190521200055-c6f3937de18c/go.mod h1:5STLWrekHfjyYwxBRVRXNOSewLJ3PWfDJd1VyTS21fI=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 h1:MkV+77GLUNo5oJ0jf870itWm3D0Sjh7+Za9gazKc5LQ=
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 h1:mZHayPoR0lNmnHyvtYjDeq0zlVHn9K/ZXoy17ylucdo=
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5/go.mod h1:GEXHk5HgEKCvEIIrSpFI3ozzG5xOKA2DVlEX/gGnewM=
...
...
@@ -920,6 +936,7 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/sykesm/zap-logfmt v0.0.3 h1:3Wrhf7+I9JEUD8B6KPtDAr9j2jrS0/EPLy7GCE1t/+U=
github.com/sykesm/zap-logfmt v0.0.3/go.mod h1:AuBd9xQjAe3URrWT1BBDk2v2onAZHkZkWRMiYZXiZWA=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d/go.mod h1:9OrXJhf154huy1nPWmuSrkgjPUtUNhA+Zmy+6AESzuA=
...
...
@@ -963,6 +980,7 @@ github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV
github.com/wangjia184/sortedset v0.0.0-20160527075905-f5d03557ba30/go.mod h1:YkocrP2K2tcw938x9gCOmT5G5eCD6jsTz0SZuyAqwIE=
github.com/wangjia184/sortedset v0.0.0-20210325043434-64dd27e173e2 h1:ViCftzy+iQHmxIJPZqJH3i0znSxFufq075LnMwt2/VQ=
github.com/wangjia184/sortedset v0.0.0-20210325043434-64dd27e173e2/go.mod h1:YkocrP2K2tcw938x9gCOmT5G5eCD6jsTz0SZuyAqwIE=
github.com/wasmerio/go-ext-wasm v0.3.1 h1:G95XP3fE2FszQSwIU+fHPBYzD0Csmd2ef33snQXNA5Q=
github.com/wasmerio/go-ext-wasm v0.3.1/go.mod h1:VGyarTzasuS7k5KhSIGpM3tciSZlkP31Mp9VJTHMMeI=
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 h1:EKhdznlJHPMoKr0XTrX+IlJs1LH3lyx2nfr1dOlZ79k=
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1/go.mod h1:8UvriyWtv5Q5EOgjHaSseUEdkQfvwFv1I/In/O2M9gc=
...
...
@@ -1275,10 +1293,14 @@ gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMy
gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o=
gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno=
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/jcmturner/aescts.v1 v1.0.1 h1:cVVZBK2b1zY26haWB4vbBiZrfFQnfbTVrE3xZq6hrEw=
gopkg.in/jcmturner/aescts.v1 v1.0.1/go.mod h1:nsR8qBOg+OucoIW+WMhB3GspUQXq9XorLnQb9XtvcOo=
gopkg.in/jcmturner/dnsutils.v1 v1.0.1 h1:cIuC1OLRGZrld+16ZJvvZxVJeKPsvd5eUIvxfoN5hSM=
gopkg.in/jcmturner/dnsutils.v1 v1.0.1/go.mod h1:m3v+5svpVOhtFAP/wSz+yzh4Mc0Fg7eRhxkJMWSIz9Q=
gopkg.in/jcmturner/goidentity.v3 v3.0.0/go.mod h1:oG2kH0IvSYNIu80dVAyu/yoefjq1mNfM5bm88whjWx4=
gopkg.in/jcmturner/gokrb5.v7 v7.5.0 h1:a9tsXlIDD9SKxotJMK3niV7rPZAJeX2aD/0yg3qlIrg=
gopkg.in/jcmturner/gokrb5.v7 v7.5.0/go.mod h1:l8VISx+WGYp+Fp7KRbsiUuXTTOnxIc3Tuvyavf11/WM=
gopkg.in/jcmturner/rpc.v1 v1.1.0 h1:QHIUxTX1ISuAv9dD2wJ9HWQVuWDX/Zc0PfeC2tjc4rU=
gopkg.in/jcmturner/rpc.v1 v1.1.0/go.mod h1:YIdkC4XfD6GXbzje11McwsDuOlZQSb9W4vfLvuNnlv8=
gopkg.in/mgo.v2 v2.0.0-20160818015218-f2b6f6c918c4 h1:hILp2hNrRnYjZpmIbx70psAHbBSEcQ1NIzDcUbJ1b6g=
gopkg.in/mgo.v2 v2.0.0-20160818015218-f2b6f6c918c4/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
...
...
internal/app/sidecar.go
View file @
0cdf9a37
...
...
@@ -19,6 +19,7 @@ import (
"github.com/link33/sidecar/internal/peermgr"
"github.com/link33/sidecar/internal/repo"
"github.com/link33/sidecar/internal/router"
"github.com/link33/sidecar/internal/rulemgr"
"github.com/link33/sidecar/internal/txcrypto"
"github.com/link33/sidecar/pkg/plugins"
"github.com/link33/sidecar/tool"
...
...
@@ -65,7 +66,10 @@ func NewSidecar(repoRoot string, config *repo.Config) (internal.Launcher, error)
r
.
Adds
(
clientPort
)
mg
,
err
:=
manger
.
NewManager
(
addr
.
String
(),
pm
,
appchainMgr
,
loggers
.
Logger
(
loggers
.
Manger
))
tool
.
Asset
(
err
)
apiServer
:=
api
.
NewServer
(
config
,
pm
,
loggers
.
Logger
(
loggers
.
ApiServer
))
rule
,
err
:=
rulemgr
.
New
(
store
,
loggers
.
Logger
(
loggers
.
Rule
))
tool
.
Asset
(
err
)
apiServer
:=
api
.
NewServer
(
config
,
pm
,
rule
,
loggers
.
Logger
(
loggers
.
ApiServer
))
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
return
&
App
{
storage
:
store
,
...
...
internal/checker/checker.go
View file @
0cdf9a37
package
checker
import
"github.com/link33/sidecar/model/pb"
import
(
"fmt"
"sync"
"github.com/link33/sidecar/internal/rulemgr"
"github.com/link33/sidecar/model/pb"
)
type
MockChecker
struct
{}
func
(
ck
*
MockChecker
)
Check
(
ibtp
*
pb
.
IBTP
)
error
{
return
nil
}
type
checker
struct
{
ruleMgr
*
rulemgr
.
RuleMgr
appchainCache
sync
.
Map
}
type
appchainRule
struct
{
codeAddress
string
}
func
NewChecker
(
ruleMgr
*
rulemgr
.
RuleMgr
)
Checker
{
return
&
checker
{
ruleMgr
:
ruleMgr
,
}
}
func
(
c
*
checker
)
Check
(
ibtp
*
pb
.
IBTP
)
error
{
// todo check err
// chainID := ibtp.From
var
validatorAddr
string
var
trustRoot
string
// todo
ok
,
err
:=
c
.
ruleMgr
.
Validate
(
validatorAddr
,
ibtp
.
From
,
ibtp
.
Proof
,
ibtp
.
Payload
,
trustRoot
)
if
err
!=
nil
{
return
err
}
if
!
ok
{
return
fmt
.
Errorf
(
"rule check failed"
)
}
return
nil
}
internal/loggers/loggers.go
View file @
0cdf9a37
...
...
@@ -19,6 +19,7 @@ const (
Swarm
=
"swarm"
Syncer
=
"syncer"
Manger
=
"manger"
Rule
=
"rule"
)
var
w
*
loggerWrapper
...
...
@@ -49,9 +50,10 @@ func InitializeLogger(config *repo.Config) {
m
[
Syncer
]
.
Logger
.
SetLevel
(
log
.
ParseLevel
(
config
.
Log
.
Module
.
Syncer
))
m
[
PeerMgr
]
=
log
.
NewWithModule
(
PeerMgr
)
m
[
PeerMgr
]
.
Logger
.
SetLevel
(
log
.
ParseLevel
(
config
.
Log
.
Module
.
PeerMgr
))
m
[
Manger
]
=
log
.
NewWithModule
(
Manger
)
m
[
Manger
]
.
Logger
.
SetLevel
(
log
.
ParseLevel
(
config
.
Log
.
Module
.
Manger
))
m
[
Rule
]
=
log
.
NewWithModule
(
Rule
)
m
[
Rule
]
.
Logger
.
SetLevel
(
log
.
ParseLevel
(
config
.
Log
.
Module
.
Rule
))
w
=
&
loggerWrapper
{
loggers
:
m
}
}
...
...
internal/repo/config.go
View file @
0cdf9a37
...
...
@@ -67,6 +67,7 @@ type LogModule struct {
Swarm
string
`toml:"swarm" json:"swarm" json:"swarm,omitempty"`
Syncer
string
`toml:"syncer" json:"syncer" json:"syncer,omitempty"`
Manger
string
`toml:"manger" json:"manger" json:"manger,omitempty"`
Rule
string
`toml:"rule" json:"rule" json:"rule,omitempty"`
}
// Appchain are configs about appchain
...
...
internal/rulemgr/code_ledger.go
0 → 100644
View file @
0cdf9a37
package
rulemgr
import
(
"github.com/meshplus/bitxhub-kit/storage"
"github.com/meshplus/bitxhub-kit/types"
)
const
rulePrefix
=
"validation-rule-"
type
CodeLedger
struct
{
storage
storage
.
Storage
}
func
(
l
*
CodeLedger
)
GetCode
(
address
*
types
.
Address
)
[]
byte
{
key
:=
rulePrefix
+
address
.
String
()
code
:=
l
.
storage
.
Get
([]
byte
(
key
))
return
code
}
func
(
l
*
CodeLedger
)
SetCode
(
address
*
types
.
Address
,
code
[]
byte
)
error
{
key
:=
rulePrefix
+
address
.
String
()
l
.
storage
.
Put
([]
byte
(
key
),
code
)
return
nil
}
internal/rulemgr/handle.go
0 → 100644
View file @
0cdf9a37
package
rulemgr
import
(
"encoding/json"
"github.com/meshplus/bitxhub-kit/types"
"github.com/link33/sidecar/internal/port"
"github.com/link33/sidecar/model/pb"
)
func
(
rm
*
RuleMgr
)
HandleRule
(
p
port
.
Port
,
msg
*
pb
.
Message
)
{
data
:=
msg
.
Payload
.
Data
rule
:=
&
Rule
{}
if
err
:=
json
.
Unmarshal
(
data
,
rule
);
err
!=
nil
{
rm
.
logger
.
Error
(
err
)
return
}
ok
:=
true
err
:=
rm
.
Ledger
.
SetCode
(
types
.
NewAddressByStr
(
rule
.
Address
),
rule
.
Code
)
if
err
!=
nil
{
ok
=
false
rm
.
logger
.
Error
(
err
)
}
res
:=
RuleResponse
{
Ok
:
ok
,
}
ackData
,
err
:=
json
.
Marshal
(
res
)
if
err
!=
nil
{
rm
.
logger
.
Error
(
err
)
return
}
err
=
p
.
AsyncSend
(
pb
.
Msg
(
pb
.
Message_ACK
,
true
,
ackData
))
if
err
!=
nil
{
rm
.
logger
.
Error
(
err
)
}
}
internal/rulemgr/rule_mgr.go
0 → 100644
View file @
0cdf9a37
package
rulemgr
import
(
"sync"
"github.com/meshplus/bitxhub-core/validator"
"github.com/meshplus/bitxhub-kit/storage"
"github.com/sirupsen/logrus"
)
type
Rule
struct
{
Code
[]
byte
`json:"code"`
Address
string
`json:"address"`
}
type
RuleResponse
struct
{
Ok
bool
`json:"ok"`
Content
string
`json:"content"`
}
type
RuleMgr
struct
{
Ledger
*
CodeLedger
Ve
*
validator
.
ValidationEngine
logger
logrus
.
FieldLogger
}
func
New
(
storage
storage
.
Storage
,
logger
logrus
.
FieldLogger
)
(
*
RuleMgr
,
error
)
{
ledger
:=
&
CodeLedger
{
storage
:
storage
,
}
instances
:=
&
sync
.
Map
{}
ve
:=
validator
.
NewValidationEngine
(
ledger
,
instances
,
logger
)
rm
:=
&
RuleMgr
{
Ledger
:
ledger
,
Ve
:
ve
,
logger
:
logger
,
}
return
rm
,
nil
}
func
(
rm
*
RuleMgr
)
Validate
(
address
,
from
string
,
proof
,
payload
[]
byte
,
validators
string
)
(
bool
,
error
)
{
ok
,
err
:=
rm
.
Ve
.
Validate
(
address
,
from
,
proof
,
payload
,
validators
)
return
ok
,
err
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment