]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cypherpunks.ru/nncp/call.go
Simple rate limiter
[nncp.git] / src / cypherpunks.ru / nncp / call.go
index fa1aff7ccc8f666b87dea4f767d77c23aa08f292..fbdd05b014d2244061ebdab9af65d27f8b26414a 100644 (file)
@@ -1,6 +1,6 @@
 /*
 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
-Copyright (C) 2016-2017 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2016-2018 Sergey Matveev <stargrave@stargrave.org>
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -21,9 +21,22 @@ package nncp
 import (
        "net"
        "strconv"
+
+       "github.com/gorhill/cronexpr"
 )
 
-func (ctx *Ctx) CallNode(node *Node, addrs []string, nice uint8, xxOnly *TRxTx, onlineDeadline int) (isGood bool) {
+type Call struct {
+       Cron           *cronexpr.Expression
+       Nice           uint8
+       Xx             TRxTx
+       RxRate         int
+       TxRate         int
+       Addr           *string
+       OnlineDeadline uint
+       MaxOnlineTime  uint
+}
+
+func (ctx *Ctx) CallNode(node *Node, addrs []string, nice uint8, xxOnly TRxTx, rxRate, txRate int, onlineDeadline, maxOnlineTime uint) (isGood bool) {
        for _, addr := range addrs {
                sds := SDS{"node": node.Id, "addr": addr}
                ctx.LogD("call", sds, "dialing")
@@ -33,7 +46,16 @@ func (ctx *Ctx) CallNode(node *Node, addrs []string, nice uint8, xxOnly *TRxTx,
                        continue
                }
                ctx.LogD("call", sds, "connected")
-               state, err := ctx.StartI(conn, node.Id, nice, xxOnly, onlineDeadline)
+               state, err := ctx.StartI(
+                       conn,
+                       node.Id,
+                       nice,
+                       xxOnly,
+                       rxRate,
+                       txRate,
+                       onlineDeadline,
+                       maxOnlineTime,
+               )
                if err == nil {
                        ctx.LogI("call-start", sds, "connected")
                        state.Wait()