mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-10 15:07:24 +00:00
package rename peer -> p2p
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// Originally Copyright (c) 2013-2014 Conformal Systems LLC.
|
||||
// https://github.com/conformal/btcd/blob/master/LICENSE
|
||||
|
||||
package peer
|
||||
package p2p
|
||||
|
||||
import (
|
||||
crand "crypto/rand" // for seeding
|
||||
@@ -1,4 +1,4 @@
|
||||
package peer
|
||||
package p2p
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -1,4 +1,4 @@
|
||||
package peer
|
||||
package p2p
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
@@ -1,4 +1,4 @@
|
||||
package peer
|
||||
package p2p
|
||||
|
||||
import (
|
||||
"net"
|
||||
@@ -1,4 +1,4 @@
|
||||
package peer
|
||||
package p2p
|
||||
|
||||
import (
|
||||
"github.com/cihub/seelog"
|
||||
@@ -1,4 +1,4 @@
|
||||
package peer
|
||||
package p2p
|
||||
|
||||
import (
|
||||
. "github.com/tendermint/tendermint/binary"
|
||||
@@ -2,7 +2,7 @@
|
||||
// Originally Copyright (c) 2013-2014 Conformal Systems LLC.
|
||||
// https://github.com/conformal/btcd/blob/master/LICENSE
|
||||
|
||||
package peer
|
||||
package p2p
|
||||
|
||||
import (
|
||||
. "github.com/tendermint/tendermint/binary"
|
||||
@@ -1,4 +1,4 @@
|
||||
package peer
|
||||
package p2p
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -1,4 +1,4 @@
|
||||
package peer
|
||||
package p2p
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -12,7 +12,12 @@ var pexErrInvalidMessage = errors.New("Invalid PEX message")
|
||||
|
||||
const pexCh = "PEX"
|
||||
|
||||
func peerExchangeHandler(s *Switch, addrBook *AddrBook) {
|
||||
/*
|
||||
The PexHandler routine should be started separately from the Switch.
|
||||
It handles basic PEX communciation.
|
||||
The application is responsible for sending out a PexRequestMessage.
|
||||
*/
|
||||
func PexHandler(s *Switch, addrBook *AddrBook) {
|
||||
|
||||
for {
|
||||
inPkt := s.Receive(pexCh) // {Peer, Time, Packet}
|
||||
@@ -25,7 +30,7 @@ func peerExchangeHandler(s *Switch, addrBook *AddrBook) {
|
||||
msg := decodeMessage(inPkt.Bytes)
|
||||
|
||||
switch msg.(type) {
|
||||
case *pexRequestMessage:
|
||||
case *PexRequestMessage:
|
||||
// inPkt.Peer requested some peers.
|
||||
// TODO: prevent abuse.
|
||||
addrs := addrBook.GetSelection()
|
||||
@@ -65,7 +70,7 @@ const (
|
||||
func decodeMessage(bz ByteSlice) (msg Message) {
|
||||
switch Byte(bz[0]) {
|
||||
case pexTypeRequest:
|
||||
return &pexRequestMessage{}
|
||||
return &PexRequestMessage{}
|
||||
case pexTypeResponse:
|
||||
return readPexResponseMessage(bytes.NewReader(bz[1:]))
|
||||
default:
|
||||
@@ -76,10 +81,10 @@ func decodeMessage(bz ByteSlice) (msg Message) {
|
||||
/*
|
||||
A response with peer addresses
|
||||
*/
|
||||
type pexRequestMessage struct {
|
||||
type PexRequestMessage struct {
|
||||
}
|
||||
|
||||
func (m *pexRequestMessage) WriteTo(w io.Writer) (n int64, err error) {
|
||||
func (m *PexRequestMessage) WriteTo(w io.Writer) (n int64, err error) {
|
||||
n, err = WriteOnto(pexTypeRequest, w, n, err)
|
||||
return
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package peer
|
||||
package p2p
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@@ -49,18 +49,9 @@ func NewSwitch(channels []ChannelDescriptor) *Switch {
|
||||
stopped: 0,
|
||||
}
|
||||
|
||||
// automatically start
|
||||
s.start()
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *Switch) start() {
|
||||
// Handle PEX messages
|
||||
// TODO: hmm
|
||||
// go peerExchangeHandler(c)
|
||||
}
|
||||
|
||||
func (s *Switch) Stop() {
|
||||
log.Infof("Stopping switch")
|
||||
// lock
|
||||
@@ -1,4 +1,4 @@
|
||||
package peer
|
||||
package p2p
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@@ -1,4 +1,4 @@
|
||||
package peer
|
||||
package p2p
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
Reference in New Issue
Block a user