mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
General:
- Message encapsulation is temporary until integration with whisper
Incoming message handling:
- Implements a dispatcher for registering handler functions to pss topics
- Handlers can be any sort of function, and can send/receive on p2p.MsgReadWriter
- Actual p2p.Protocol handling now as pluggable convenience function
Sending and routing:
- Added temporary cache solution based on message hash digest
- Send and forward split up as separate methods
- Send is now payload agnostic (p2p.Protocol replies massaged in p2p.MsgWriter)
Tests:
- TestPssRandom...
Sends PSS between randomly selected nodes in different population magnitudes
- TestPssFullLinearEcho
A->B->C->B->A ping/pong over pss, where A and C are running pss
- TestPssFullRandom50Pct
10 nodes where 5 are running pss, 5 sends to/from random nodes
(messages currently get stuck in kad. routing, discarded by cache block)
- Protocoltester tests status unknown
55 lines
1.7 KiB
Go
55 lines
1.7 KiB
Go
// Copyright 2016 The go-ethereum Authors
|
|
// This file is part of the go-ethereum library.
|
|
//
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
package common
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
LabelLength = 8
|
|
)
|
|
|
|
// PrettyDuration is a pretty printed version of a time.Duration value that cuts
|
|
// the unnecessary precision off from the formatted textual representation.
|
|
type PrettyDuration time.Duration
|
|
|
|
var prettyDurationRe = regexp.MustCompile(`\.[0-9]+`)
|
|
|
|
// String implements the Stringer interface, allowing pretty printing of duration
|
|
// values rounded to three decimals.
|
|
func (d PrettyDuration) String() string {
|
|
label := fmt.Sprintf("%v", time.Duration(d))
|
|
if match := prettyDurationRe.FindString(label); len(match) > 4 {
|
|
label = strings.Replace(label, match, match[:4], 1)
|
|
}
|
|
return label
|
|
}
|
|
|
|
// useful for segfault safe reduction of log clutter
|
|
func ByteLabel(addr []byte) (b [LabelLength]byte) {
|
|
//b = make([LabelLength]byte)
|
|
if len(addr) < LabelLength {
|
|
copy(b[LabelLength - len(addr) - 1:len(addr)], addr[:])
|
|
} else {
|
|
copy(b[:], addr[:LabelLength])
|
|
}
|
|
return b
|
|
}
|