Skip to content

Commit

Permalink
update quic connection timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricfung committed May 15, 2024
1 parent 5d2f18e commit a79bf32
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 38 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ address: XINBpBaDKtcu5SBuuqE1pwMrdeFvyCwFChdjLS23ewKdoLbURL4iJYCXLvsXP1nVbB3C
view key: be25d97ba8eb80336998facfb033f71713f9c1cabdc417478f831c749fcd9001
spend key: 5189b286e5717ea36435a29dfb1aaddebad5e216b05e8b4de59693dfb9fe1f06
$ mixin signcustodiandeposit -receiver XINBpBaDKtcu5SBuuqE1pwMrdeFvyCwFChdjLS23ewKdoLbURL4iJYCXLvsXP1nVbB3CGRbWg6UgVH8AWVgjSgmenMsrgpRY \
-custodian CUSODIANPRIVATEVIEWPRIVATESPEND \
$ mixin signcustodiandeposit -custodian CUSODIANPRIVATEVIEWPRIVATESPEND \
-receiver XINBpBaDKtcu5SBuuqE1pwMrdeFvyCwFChdjLS23ewKdoLbURL4iJYCXLvsXP1nVbB3CGRbWg6UgVH8AWVgjSgmenMsrgpRY \
-asset a99c2e0e2b1da4d648755ef19bd95139acbbe6564cfb06dec7cd34931ca72cdc \
-chain 8dd50817c082cdcdd6f167514928767a4b52426997bd6d4930eca101c5ff8a27 \
-asset_key 0xa974c709cfb4566686553a20790685a47aceaa33 \
Expand Down
33 changes: 0 additions & 33 deletions kernel/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,39 +460,6 @@ func (node *Node) BuildGraph() []*p2p.SyncPoint {
return points
}

func (node *Node) Authenticate(msg []byte) (crypto.Hash, string, error) {
if len(msg) < 8+len(crypto.Hash{})+len(crypto.Signature{}) {
return crypto.Hash{}, "", fmt.Errorf("peer authentication message malformated %d", len(msg))
}
ts := binary.BigEndian.Uint64(msg[:8])
if clock.Now().Unix()-int64(ts) > 3 {
return crypto.Hash{}, "", fmt.Errorf("peer authentication message timeout %d %d", ts, clock.Now().Unix())
}

var signer common.Address
copy(signer.PublicSpendKey[:], msg[8:40])
signer.PublicViewKey = signer.PublicSpendKey.DeterministicHashDerive().Public()
peerId := signer.Hash().ForNetwork(node.networkId)
if peerId == node.IdForNetwork {
return crypto.Hash{}, "", fmt.Errorf("peer authentication invalid consensus peer %s", peerId)
}
peer := node.GetAcceptedOrPledgingNode(peerId)

if peer != nil && peer.Signer.Hash() != signer.Hash() {
return crypto.Hash{}, "", fmt.Errorf("peer authentication invalid consensus peer %s", peerId)
}

var sig crypto.Signature
copy(sig[:], msg[40:40+len(sig)])
mh := crypto.Blake3Hash(msg[:40])
if !signer.PublicSpendKey.Verify(mh, sig) {
return crypto.Hash{}, "", fmt.Errorf("peer authentication message signature invalid %s", peerId)
}

listener := string(msg[40+len(sig):])
return peerId, listener, nil
}

func (node *Node) SendTransactionToPeer(peerId, hash crypto.Hash) error {
tx, _, err := node.checkTxInStorage(hash)
if err != nil || tx == nil {
Expand Down
2 changes: 1 addition & 1 deletion p2p/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ func (me *Peer) authenticateNeighbor(client Client) (*Peer, error) {
}
me.receivedMetric.handle(PeerMessageTypeAuthentication)

token, err := me.handle.AuthenticateAs(me.IdForNetwork, msg.Data, 5)
token, err := me.handle.AuthenticateAs(me.IdForNetwork, msg.Data, int64(HandshakeTimeout/time.Second))
if err != nil {
auth <- err
return
Expand Down
4 changes: 2 additions & 2 deletions p2p/quic.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import (

const (
MaxIncomingStreams = 128
HandshakeTimeout = 10 * time.Second
HandshakeTimeout = 30 * time.Second
IdleTimeout = 600 * time.Second
ReadDeadline = 300 * time.Second
WriteDeadline = 10 * time.Second
WriteDeadline = 30 * time.Second
)

type QuicClient struct {
Expand Down

0 comments on commit a79bf32

Please sign in to comment.