package rename peer -> p2p

This commit is contained in:
Jae Kwon
2014-07-07 20:03:50 -07:00
parent 5c20d133f7
commit 61224f86c9
15 changed files with 22 additions and 26 deletions

View File

@@ -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

View File

@@ -1,4 +1,4 @@
package peer
package p2p
import (
"fmt"

View File

@@ -1,4 +1,4 @@
package peer
package p2p
import (
"bufio"

View File

@@ -1,4 +1,4 @@
package peer
package p2p
import (
"net"

View File

@@ -1,4 +1,4 @@
package peer
package p2p
import (
"github.com/cihub/seelog"

View File

@@ -1,4 +1,4 @@
package peer
package p2p
import (
. "github.com/tendermint/tendermint/binary"

View File

@@ -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"

View File

@@ -1,4 +1,4 @@
package peer
package p2p
import (
"fmt"

View File

@@ -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
}

View File

@@ -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

View File

@@ -1,4 +1,4 @@
package peer
package p2p
import (
"testing"

View File

@@ -1,4 +1,4 @@
package peer
package p2p
import (
"crypto/sha256"