From 1bf1ea056d2fb03403f8d7e4ddba68d0aea96ef7 Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Fri, 10 Nov 2017 11:46:05 +0100 Subject: [PATCH 1/2] p2p/sim: configurable unix socket read/write size --- p2p/simulations/adapters/inproc.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/p2p/simulations/adapters/inproc.go b/p2p/simulations/adapters/inproc.go index b1f86cc6b099..297bfc1df6e6 100644 --- a/p2p/simulations/adapters/inproc.go +++ b/p2p/simulations/adapters/inproc.go @@ -34,6 +34,11 @@ import ( "github.com/ethereum/go-ethereum/rpc" ) +const ( + socketReadBuffer = 5000 * 1024 + socketWriteBuffer = 5000 * 1024 +) + // SimAdapter is a NodeAdapter which creates in-memory simulation nodes and // connects them using net.Pipe or OS socket connections type SimAdapter struct { @@ -364,9 +369,27 @@ func socketPipe() (net.Conn, net.Conn, error) { if err != nil { return nil, nil, err } + + setSocketBuffer(pipe1) + setSocketBuffer(pipe2) + return pipe1, pipe2, nil } +func setSocketBuffer(conn net.Conn) { + switch v := conn.(type) { + case *net.UnixConn: + err := v.SetReadBuffer(socketReadBuffer) + if err != nil { + panic(err) + } + err = v.SetWriteBuffer(socketWriteBuffer) + if err != nil { + panic(err) + } + } +} + // netPipe wraps net.Pipe in a signature returning an error func netPipe() (net.Conn, net.Conn, error) { p1, p2 := net.Pipe() From 3a74282dd2fe99d2dd3eca1c4835f11cc168666b Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Mon, 13 Nov 2017 11:18:37 +0100 Subject: [PATCH 2/2] p2p/sim: handle error when socket buffer size update fails --- p2p/simulations/adapters/inproc.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/p2p/simulations/adapters/inproc.go b/p2p/simulations/adapters/inproc.go index 297bfc1df6e6..0ac01f1fe518 100644 --- a/p2p/simulations/adapters/inproc.go +++ b/p2p/simulations/adapters/inproc.go @@ -370,24 +370,32 @@ func socketPipe() (net.Conn, net.Conn, error) { return nil, nil, err } - setSocketBuffer(pipe1) - setSocketBuffer(pipe2) + err = setSocketBuffer(pipe1) + if err != nil { + return nil, nil, err + } + + err = setSocketBuffer(pipe2) + if err != nil { + return nil, nil, err + } return pipe1, pipe2, nil } -func setSocketBuffer(conn net.Conn) { +func setSocketBuffer(conn net.Conn) error { switch v := conn.(type) { case *net.UnixConn: err := v.SetReadBuffer(socketReadBuffer) if err != nil { - panic(err) + return err } err = v.SetWriteBuffer(socketWriteBuffer) if err != nil { - panic(err) + return err } } + return nil } // netPipe wraps net.Pipe in a signature returning an error