mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-06 12:03:47 +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
62 lines
1.1 KiB
Go
62 lines
1.1 KiB
Go
package ws
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/ethereum/go-ethereum/logger"
|
|
"github.com/ethereum/go-ethereum/logger/glog"
|
|
"github.com/ethereum/go-ethereum/rpc"
|
|
)
|
|
|
|
func init() {
|
|
glog.SetV(logger.Detail)
|
|
glog.SetToStderr(true)
|
|
}
|
|
|
|
type TestResult struct {
|
|
Foo string `json:"foo"`
|
|
}
|
|
|
|
func TestStartWSServer(t *testing.T) {
|
|
ep := "localhost:8099"
|
|
server := &Server{
|
|
Endpoint: ep,
|
|
CorsString: "*",
|
|
}
|
|
apis := []rpc.API{
|
|
{
|
|
Namespace: "pss",
|
|
Version: "0.1",
|
|
Service: makeFakeAPIHandler(),
|
|
Public: true,
|
|
},
|
|
}
|
|
go func() {
|
|
err := StartWSServer(apis, server)
|
|
t.Logf("wsserver exited: %v", err)
|
|
}()
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
client, err := rpc.DialWebsocket(context.Background(), "ws://" + ep, "ws://localhost")
|
|
if err != nil {
|
|
t.Fatalf("could not connect: %v", err)
|
|
} else {
|
|
t.Logf("client: %v", client)
|
|
client.Call(&TestResult{}, "pss_test")
|
|
}
|
|
|
|
}
|
|
|
|
func makeFakeAPIHandler() *FakeAPIHandler {
|
|
return &FakeAPIHandler{}
|
|
}
|
|
|
|
type FakeAPIHandler struct {
|
|
}
|
|
|
|
func (self *FakeAPIHandler) Test() {
|
|
glog.V(logger.Detail).Infof("in fakehandler Test()")
|
|
}
|