Skip to content

Commit

Permalink
Feature/relay4 (#81)
Browse files Browse the repository at this point in the history
* Add test cases. Bug fixes

* Fix linter errors

* Rename dsdemo to dsapp
  • Loading branch information
dpunish3r authored Nov 9, 2023
1 parent 32e4f3e commit 013c6c6
Show file tree
Hide file tree
Showing 8 changed files with 399 additions and 96 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*.so
*.dylib
main
dsdemo
dsapp
dsrelay

# Test binary, built with `go test -c`
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ install-linter: ## Installs the linter
lint: ## Runs the linter
export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/golangci-lint run

.PHONY: build-dsdemo
build-dsdemo: ## Builds datastream demo cli app (server, client, relay)
go build -o dsdemo cmd/main.go
.PHONY: build-dsapp
build-dsapp: ## Builds datastream demo cli app (server, client, relay)
go build -o dsapp cmd/main.go

.PHONY: build-dsrelay
build-dsrelay: ## Builds datastream relay cli app
Expand Down
43 changes: 24 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,20 @@ Stream relay server included in the datastream library allows scaling the number
- ExecCommand(datastreamer.CmdBookmark) -> gets entry data pointed by bookmark and fills the `.Entry` field

## DATASTREAM CLI DEMO APP
Build the binary datastream demo app (`dsdemo`):
Build the binary datastream demo app (`dsapp`):
```
make build
make build-dsapp
```
Run the app without parameters to see the available commands:
```
./dsdemo
./dsapp
```
```
NAME:
dsdemo - Run a datastream server/client/relay demo cli app
dsapp - Run a datastream server/client/relay demo cli app
USAGE:
dsdemo [global options] command [command options] [arguments...]
dsapp [global options] command [command options] [arguments...]
COMMANDS:
server Run datastream server
Expand All @@ -203,14 +203,14 @@ GLOBAL OPTIONS:
### SERVER
Use the help option to check available parameters for the server command:
```
./dsdemo help server
./dsapp help server
```
```
NAME:
dsdemo server - Run datastream server
dsapp server - Run datastream server
USAGE:
dsdemo server [command options] [arguments...]
dsapp server [command options] [arguments...]
OPTIONS:
--port value exposed port for clients to connect (default: 6900)
Expand All @@ -222,52 +222,57 @@ OPTIONS:
```
Run a datastream server with default parameters (port: `6900`, file: `datastream.bin`, log: `info`):
```
./dsdemo server
./dsapp server
```
Or run a datastream server with custom parameters:
```
./dsdemo server --port 6969 --file seqstream.bin --log warn
./dsapp server --port 6969 --file seqstream.bin --log warn
```
### CLIENT
Use the help option to check available parameters for the client command:
```
./dsdemo help client
./dsapp help client
```
```
NAME:
dsdemo client - Run datastream client
dsapp client - Run datastream client
USAGE:
dsdemo client [command options] [arguments...]
dsapp client [command options] [arguments...]
OPTIONS:
--server value datastream server address to connect (IP:port) (default: 127.0.0.1:6900)
--from value entry number to start the sync/streaming from (latest|0..N) (default: latest)
--frombookmark value bookmark to start the sync/streaming from (0..N) (has preference over --from parameter)
--header query file header information (default: false)
--entry value entry number to query data (0..N)
--bookmark value entry bookmark to query entry data pointed by it (0..N)
--log value log level (debug|info|warn|error) (default: info)
--help, -h show help
```
Run a datastream client with default parameters (server: `127.0.0.1:6900`, from: `latest`, log: `info`)
```
./dsdemo client
./dsapp client
```
Or run a datastream client with custom parameters:
```
./dsdemo client --server 127.0.0.1:6969 --from 0 --log debug
./dsapp client --server 127.0.0.1:6969 --from 0 --log debug
```
Or just get the current stream header file information:
```
./dsapp client --server 127.0.0.1:6969 --header
```
### RELAY
Use the help option to check available parameters for the relay command:
```
./dsdemo help relay
./dsapp help relay
```
```
NAME:
dsdemo relay - Run datastream relay
dsapp relay - Run datastream relay
USAGE:
dsdemo relay [command options] [arguments...]
dsapp relay [command options] [arguments...]
OPTIONS:
--server value datastream server address to connect (IP:port) (default: 127.0.0.1:6900)
Expand All @@ -278,7 +283,7 @@ OPTIONS:
```
Run a datastream relay with default parameters (server: `127.0.0.1:6900`, port: `7900`, file: `datarelay.bin`, log: `info`)
```
./dsdemo relay
./dsapp relay
```

## USE CASE: zkEVM SEQUENCER ENTRIES
Expand Down
17 changes: 17 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ func main() {
Usage: "bookmark to start the sync/streaming from (0..N) (has preference over --from parameter)",
Value: "none",
},
&cli.BoolFlag{
Name: "header",
Usage: "query file header information",
Value: false,
},
&cli.StringFlag{
Name: "entry",
Usage: "entry number to query data (0..N)",
Expand Down Expand Up @@ -340,6 +345,7 @@ func runClient(ctx *cli.Context) error {
}
from := ctx.String("from")
fromBookmark := ctx.String("frombookmark")
queryHeader := ctx.Bool("header")
queryEntry := ctx.String("entry")
queryBookmark := ctx.String("bookmark")

Expand All @@ -358,6 +364,17 @@ func runClient(ctx *cli.Context) error {
return err
}

// Query file header information
if queryHeader {
err = c.ExecCommand(datastreamer.CmdHeader)
if err != nil {
log.Infof("Error: %v", err)
} else {
log.Infof("QUERY HEADER: TotalEntries[%d] TotalLength[%d]", c.Header.TotalEntries, c.Header.TotalLength)
}
return nil
}

// Query entry option
if queryEntry != "none" {
qEntry, err := strconv.Atoi(queryEntry)
Expand Down
Loading

0 comments on commit 013c6c6

Please sign in to comment.