Skip to content
Merged
3 changes: 3 additions & 0 deletions conf/limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package conf

import "time"

const (
// MaxPendingTxsPerAccount defines the limit of pending transactions of one account.
MaxPendingTxsPerAccount = 1000
Expand All @@ -34,4 +36,5 @@ const (
// block producers.
MaxTxBroadcastTTL = 1
MaxCachedBlock = 1000
TCPDialTimeout = 10 * time.Second
)
3 changes: 2 additions & 1 deletion crypto/etls/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

"github.com/pkg/errors"

"github.com/CovenantSQL/CovenantSQL/conf"
"github.com/CovenantSQL/CovenantSQL/utils/log"
)

Expand Down Expand Up @@ -57,7 +58,7 @@ func NewConn(c net.Conn, cipher *Cipher) *CryptoConn {
// Dial connects to a address with a Cipher
// address should be in the form of host:port.
func Dial(network, address string, cipher *Cipher) (c *CryptoConn, err error) {
conn, err := net.Dial(network, address)
conn, err := net.DialTimeout(network, address, conf.TCPDialTimeout)
if err != nil {
log.WithField("addr", address).WithError(err).Error("connect failed")
return
Expand Down
10 changes: 10 additions & 0 deletions crypto/etls/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,13 @@ func TestCryptoConn_RW(t *testing.T) {
wg.Wait()
})
}

func TestDialTimeout(t *testing.T) {
Convey("Test dial timeout", t, func(c C) {
_, err := Dial("tcp", "240.0.0.1:8080", NewCipher([]byte("")))
nerr, ok := err.(net.Error)
So(ok, ShouldBeTrue)
So(nerr.Timeout(), ShouldBeTrue)
})

}
3 changes: 2 additions & 1 deletion naconn/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/pkg/errors"

"github.com/CovenantSQL/CovenantSQL/conf"
"github.com/CovenantSQL/CovenantSQL/crypto/etls"
"github.com/CovenantSQL/CovenantSQL/crypto/hash"
"github.com/CovenantSQL/CovenantSQL/crypto/kms"
Expand Down Expand Up @@ -195,7 +196,7 @@ func DialEx(remote proto.NodeID, isAnonymous bool) (conn net.Conn, err error) {
}

cipher := etls.NewCipher(symmetricKey)
iconn, err := net.Dial("tcp", nodeAddr)
iconn, err := net.DialTimeout("tcp", nodeAddr, conf.TCPDialTimeout)
if err != nil {
err = errors.Wrapf(err, "connect to node %s failed", nodeAddr)
return
Expand Down
21 changes: 21 additions & 0 deletions naconn/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"testing"
"time"

"github.com/pkg/errors"
. "github.com/smartystreets/goconvey/convey"

"github.com/CovenantSQL/CovenantSQL/conf"
Expand Down Expand Up @@ -70,6 +71,26 @@ func (r *simpleResolver) ResolveEx(id *proto.RawNodeID) (*proto.Node, error) {
}

func TestNAConn(t *testing.T) {
Convey("Test dial timeout", t, func(c C) {
// Register node with invalid IP address
resolver := &simpleResolver{}
nodeinfo := thisNode()
So(nodeinfo, ShouldNotBeNil)
resolver.registerNode(&proto.Node{
Addr: "240.0.0.1:8080",
ID: nodeinfo.ID,
PublicKey: nodeinfo.PublicKey,
Nonce: nodeinfo.Nonce,
})
// Register resolver
RegisterResolver(resolver)
// Test dial timeout
_, err := Dial(nodeinfo.ID)
nerr, ok := errors.Cause(err).(net.Error)
t.Logf("err: %v\n", err)
So(ok, ShouldBeTrue)
So(nerr.Timeout(), ShouldBeTrue)
})
Convey("Test simple NAConn", t, func(c C) {
l, err := net.Listen("tcp", "localhost:0")
So(err, ShouldBeNil)
Expand Down
8 changes: 0 additions & 8 deletions route/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ const (
DBCCall
// SQLCAdviseNewBlock is used by sqlchain to advise new block between adjacent node
SQLCAdviseNewBlock
// SQLCAdviseBinLog is usd by sqlchain to advise binlog between adjacent node
SQLCAdviseBinLog
// SQLCAdviseAckedQuery is used by sqlchain to advice response query between adjacent node
SQLCAdviseAckedQuery
// SQLCFetchBlock is used by sqlchain to fetch block from adjacent nodes
SQLCFetchBlock
// SQLCSignBilling is used by sqlchain to response billing signature for periodic billing request
Expand Down Expand Up @@ -160,10 +156,6 @@ func (s RemoteFunc) String() string {
return "DBC.Call"
case SQLCAdviseNewBlock:
return "SQLC.AdviseNewBlock"
case SQLCAdviseBinLog:
return "SQLC.AdviseBinLog"
case SQLCAdviseAckedQuery:
return "SQLC.AdviseAckedQuery"
case SQLCFetchBlock:
return "SQLC.FetchBlock"
case SQLCSignBilling:
Expand Down
3 changes: 2 additions & 1 deletion rpc/mux/rawcaller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/pkg/errors"

"github.com/CovenantSQL/CovenantSQL/conf"
"github.com/CovenantSQL/CovenantSQL/rpc"
)

Expand Down Expand Up @@ -59,7 +60,7 @@ func (c *RawCaller) resetClient() (err error) {
}

var conn net.Conn
if conn, err = net.Dial("tcp", c.targetAddr); err != nil {
if conn, err = net.DialTimeout("tcp", c.targetAddr, conf.TCPDialTimeout); err != nil {
err = errors.Wrapf(err, "dial to target %s failed", c.targetAddr)
return
}
Expand Down
Loading