Skip to content

Commit

Permalink
Add cli flag for price
Browse files Browse the repository at this point in the history
Signed-off-by: Yilun <[email protected]>
  • Loading branch information
yilunzhang committed Jul 16, 2020
1 parent f5feb7d commit 96a9604
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
22 changes: 21 additions & 1 deletion examples/http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import (
"net/http"
"strings"

"github.com/nknorg/ncp-go"
nkn "github.com/nknorg/nkn-sdk-go"
ts "github.com/nknorg/nkn-tuna-session"
"github.com/nknorg/tuna"
)

const (
Expand All @@ -30,6 +32,11 @@ func main() {
listen := flag.Bool("l", false, "listen")
serveDir := flag.String("dir", ".", "serve directory")
httpAddr := flag.String("http", ":8080", "http listen address")
tunaCountry := flag.String("country", "", `tuna service node allowed country code, separated by comma, e.g. "US" or "US,CN"`)
tunaServiceName := flag.String("tsn", "", "tuna reverse service name")
tunaSubscriptionPrefix := flag.String("tsp", "", "tuna subscription prefix")
tunaMaxPrice := flag.String("price", "0.01", "tuna reverse service max price in unit of NKN/MB")
mtu := flag.Int("mtu", 0, "ncp session mtu")

flag.Parse()

Expand All @@ -38,6 +45,12 @@ func main() {
log.Fatal(err)
}

countries := strings.Split(*tunaCountry, ",")
locations := make([]tuna.Location, len(countries))
for i := range countries {
locations[i].CountryCode = strings.TrimSpace(countries[i])
}

account, err := nkn.NewAccount(seed)
if err != nil {
log.Fatal(err)
Expand All @@ -51,7 +64,14 @@ func main() {
log.Println("Seed:", hex.EncodeToString(account.Seed()))

clientConfig := &nkn.ClientConfig{ConnectRetries: 1}
config := &ts.Config{NumTunaListeners: *numTunaListeners}
config := &ts.Config{
NumTunaListeners: *numTunaListeners,
TunaServiceName: *tunaServiceName,
TunaSubscriptionPrefix: *tunaSubscriptionPrefix,
TunaMaxPrice: *tunaMaxPrice,
TunaIPFilter: &tuna.IPFilter{Allow: locations},
SessionConfig: &ncp.Config{MTU: int32(*mtu)},
}

if *listen {
m, err := nkn.NewMultiClient(account, listenID, *numClients, false, clientConfig)
Expand Down
3 changes: 2 additions & 1 deletion examples/throughput/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func main() {
tunaCountry := flag.String("country", "", `tuna service node allowed country code, separated by comma, e.g. "US" or "US,CN"`)
tunaServiceName := flag.String("tsn", "", "tuna reverse service name")
tunaSubscriptionPrefix := flag.String("tsp", "", "tuna subscription prefix")
tunaMaxPrice := flag.String("price", "0.01", "tuna reverse service max price in unit of NKN/MB")
mtu := flag.Int("mtu", 0, "ncp session mtu")

flag.Parse()
Expand Down Expand Up @@ -141,9 +142,9 @@ func main() {
NumTunaListeners: *numTunaListeners,
TunaServiceName: *tunaServiceName,
TunaSubscriptionPrefix: *tunaSubscriptionPrefix,
TunaMaxPrice: *tunaMaxPrice,
TunaIPFilter: &tuna.IPFilter{Allow: locations},
SessionConfig: &ncp.Config{MTU: int32(*mtu)},
TunaMaxPrice: "0.01",
}

if *listen {
Expand Down

0 comments on commit 96a9604

Please sign in to comment.