aboutsummaryrefslogtreecommitdiffstats
path: root/p2p
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-05-14 23:41:43 +0800
committerFelix Lange <fjl@twurst.com>2015-05-25 07:17:14 +0800
commitdbdc5fd4b33ad98ebde72e7d934cebab1408f057 (patch)
tree79d6b8827555b0220a89456d3132f40ed0f9b291 /p2p
parent2f249fea448a10ae0986a140f5a52d8a310e57fe (diff)
downloadgo-tangerine-dbdc5fd4b33ad98ebde72e7d934cebab1408f057.tar
go-tangerine-dbdc5fd4b33ad98ebde72e7d934cebab1408f057.tar.gz
go-tangerine-dbdc5fd4b33ad98ebde72e7d934cebab1408f057.tar.bz2
go-tangerine-dbdc5fd4b33ad98ebde72e7d934cebab1408f057.tar.lz
go-tangerine-dbdc5fd4b33ad98ebde72e7d934cebab1408f057.tar.xz
go-tangerine-dbdc5fd4b33ad98ebde72e7d934cebab1408f057.tar.zst
go-tangerine-dbdc5fd4b33ad98ebde72e7d934cebab1408f057.zip
p2p: delete Server.Broadcast
Diffstat (limited to 'p2p')
-rw-r--r--p2p/peer.go14
-rw-r--r--p2p/peer_test.go39
-rw-r--r--p2p/server.go41
-rw-r--r--p2p/server_test.go42
4 files changed, 0 insertions, 136 deletions
diff --git a/p2p/peer.go b/p2p/peer.go
index c7ec08887..562fbc1b4 100644
--- a/p2p/peer.go
+++ b/p2p/peer.go
@@ -273,20 +273,6 @@ func (p *Peer) getProto(code uint64) (*protoRW, error) {
return nil, newPeerError(errInvalidMsgCode, "%d", code)
}
-// writeProtoMsg sends the given message on behalf of the given named protocol.
-// this exists because of Server.Broadcast.
-func (p *Peer) writeProtoMsg(protoName string, msg Msg) error {
- proto, ok := p.running[protoName]
- if !ok {
- return fmt.Errorf("protocol %s not handled by peer", protoName)
- }
- if msg.Code >= proto.Length {
- return newPeerError(errInvalidMsgCode, "code %x is out of range for protocol %q", msg.Code, protoName)
- }
- msg.Code += proto.offset
- return p.rw.WriteMsg(msg)
-}
-
type protoRW struct {
Protocol
in chan Msg
diff --git a/p2p/peer_test.go b/p2p/peer_test.go
index 59dcb7ba4..0ac032ab7 100644
--- a/p2p/peer_test.go
+++ b/p2p/peer_test.go
@@ -1,7 +1,6 @@
package p2p
import (
- "bytes"
"errors"
"fmt"
"math/rand"
@@ -107,44 +106,6 @@ func TestPeerProtoEncodeMsg(t *testing.T) {
}
}
-func TestPeerWriteForBroadcast(t *testing.T) {
- closer, rw, peer, peerErr := testPeer([]Protocol{discard})
- defer closer()
-
- emptymsg := func(code uint64) Msg {
- return Msg{Code: code, Size: 0, Payload: bytes.NewReader(nil)}
- }
-
- // test write errors
- if err := peer.writeProtoMsg("b", emptymsg(3)); err == nil {
- t.Errorf("expected error for unknown protocol, got nil")
- }
- if err := peer.writeProtoMsg("discard", emptymsg(8)); err == nil {
- t.Errorf("expected error for out-of-range msg code, got nil")
- } else if perr, ok := err.(*peerError); !ok || perr.Code != errInvalidMsgCode {
- t.Errorf("wrong error for out-of-range msg code, got %#v", err)
- }
-
- // setup for reading the message on the other end
- read := make(chan struct{})
- go func() {
- if err := ExpectMsg(rw, 16, nil); err != nil {
- t.Error(err)
- }
- close(read)
- }()
-
- // test successful write
- if err := peer.writeProtoMsg("discard", emptymsg(0)); err != nil {
- t.Errorf("expect no error for known protocol: %v", err)
- }
- select {
- case <-read:
- case err := <-peerErr:
- t.Fatalf("peer stopped: %v", err)
- }
-}
-
func TestPeerPing(t *testing.T) {
closer, rw, _, _ := testPeer(nil)
defer closer()
diff --git a/p2p/server.go b/p2p/server.go
index 8f768bdff..529fedbca 100644
--- a/p2p/server.go
+++ b/p2p/server.go
@@ -1,7 +1,6 @@
package p2p
import (
- "bytes"
"crypto/ecdsa"
"crypto/rand"
"errors"
@@ -14,7 +13,6 @@ import (
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/p2p/nat"
- "github.com/ethereum/go-ethereum/rlp"
)
const (
@@ -159,45 +157,6 @@ func (srv *Server) AddPeer(node *discover.Node) {
srv.staticNodes[node.ID] = node
}
-// Broadcast sends an RLP-encoded message to all connected peers.
-// This method is deprecated and will be removed later.
-func (srv *Server) Broadcast(protocol string, code uint64, data interface{}) error {
- return srv.BroadcastLimited(protocol, code, func(i float64) float64 { return i }, data)
-}
-
-// BroadcastsRange an RLP-encoded message to a random set of peers using the limit function to limit the amount
-// of peers.
-func (srv *Server) BroadcastLimited(protocol string, code uint64, limit func(float64) float64, data interface{}) error {
- var payload []byte
- if data != nil {
- var err error
- payload, err = rlp.EncodeToBytes(data)
- if err != nil {
- return err
- }
- }
- srv.lock.RLock()
- defer srv.lock.RUnlock()
-
- i, max := 0, int(limit(float64(len(srv.peers))))
- for _, peer := range srv.peers {
- if i >= max {
- break
- }
-
- if peer != nil {
- var msg = Msg{Code: code}
- if data != nil {
- msg.Payload = bytes.NewReader(payload)
- msg.Size = uint32(len(payload))
- }
- peer.writeProtoMsg(protocol, msg)
- i++
- }
- }
- return nil
-}
-
// Start starts running the server.
// Servers can be re-used and started again after stopping.
func (srv *Server) Start() (err error) {
diff --git a/p2p/server_test.go b/p2p/server_test.go
index 55fc81572..6f7aaf8e1 100644
--- a/p2p/server_test.go
+++ b/p2p/server_test.go
@@ -1,12 +1,9 @@
package p2p
import (
- "bytes"
"crypto/ecdsa"
- "io"
"math/rand"
"net"
- "sync"
"testing"
"time"
@@ -121,45 +118,6 @@ func TestServerDial(t *testing.T) {
}
}
-func TestServerBroadcast(t *testing.T) {
- var connected sync.WaitGroup
- srv := startTestServer(t, func(p *Peer) {
- p.running = matchProtocols([]Protocol{discard}, []Cap{discard.cap()}, p.rw)
- connected.Done()
- })
- defer srv.Stop()
-
- // create a few peers
- var conns = make([]net.Conn, 8)
- connected.Add(len(conns))
- deadline := time.Now().Add(3 * time.Second)
- dialer := &net.Dialer{Deadline: deadline}
- for i := range conns {
- conn, err := dialer.Dial("tcp", srv.ListenAddr)
- if err != nil {
- t.Fatalf("conn %d: dial error: %v", i, err)
- }
- defer conn.Close()
- conn.SetDeadline(deadline)
- conns[i] = conn
- }
- connected.Wait()
-
- // broadcast one message
- srv.Broadcast("discard", 0, []string{"foo"})
- golden := unhex("66e94d166f0a2c3b884cfa59ca34")
-
- // check that the message has been written everywhere
- for i, conn := range conns {
- buf := make([]byte, len(golden))
- if _, err := io.ReadFull(conn, buf); err != nil {
- t.Errorf("conn %d: read error: %v", i, err)
- } else if !bytes.Equal(buf, golden) {
- t.Errorf("conn %d: msg mismatch\ngot: %x\nwant: %x", i, buf, golden)
- }
- }
-}
-
// This test checks that connections are disconnected
// just after the encryption handshake when the server is
// at capacity.