Skip to content
Snippets Groups Projects
Select Git revision
  • 8fde09bf5b40f82559c2cf7333b182acde468d02
  • develop default protected
  • congestioncontrol
  • merge-v-data-collection-spammer-0.8.2
  • WIP-merge-v-data-collection-spammer-0.8.2
  • merge-v-data-collection-spammer-0.7.7
  • tmp
  • test-masterpow-fixing
  • test-masterpow
  • test-echo
  • v-data-collection
  • v-data-collection-spammer
  • tmp-dump-spam-info
  • dump-msg-info-0.3.1
  • test-dump-message-info
  • spammer-exprandom
  • extra/tutorial
  • without_tipselection
  • hacking-docker-network
  • hacking-docker-network-0.2.3
  • master
  • v0.2.3
22 results

server_test.go

Blame
  • user avatar
    Wolfgang Welz authored and GitHub committed
    * :sparkles: GetNextCandidate selection added
    
    * :bug: Recompile salt.proto
    
    * :recycle: Refactor peer IDs completely
    
    * :bug: Recompile proto sources
    
    * :construction: WIP
    
    * :ok_hand: renamed to sort
    
    * :construction: Return requested peers on request
    
    * :sparkles: Kepp track how ofter a managed peer was verified
    
    * :wrench: sort adapted to the new peer
    
    * :construction: Query verified peers for new peers
    
    * :construction: WIP
    
    * :white_check_mark: Add manager tests
    
    * :bento: Add peering messages to protobuf
    
    * :art: Make Salt methods consistent with Peer
    
    * :sparkles: Handle peering messages
    
    * :construction: WIP
    
    * :bug: Add To filed to PeersRequest
    
    * :white_check_mark: Add PeersRequest test
    
    * :zap: Adding PeersRequest benchmark
    
    * :art: Move mpeer and helper functions to own file
    
    * :bug: Bump peer only once on reverification
    
    * :construction: WIP
    
    * :bug:
    
    * :construction: WIP
    
    * :bug: Increase buffer to prevent deadlocks
    
    * :zap: Remove unnecessary lock
    
    * :white_check_mark: Add peering request test
    
    * :white_check_mark: Make tests deterministic by triggering reverify
    
    * :construction: WIP
    
    * :lock: fixing concurrency issues
    
    * :white_check_mark: testManager improved
    
    * :bug: Don't send PeeringResponse for invalid salt
    
    * :construction: WIP
    
    * :construction: WIP
    
    * :pencil: removed commented code
    
    * :construction: WIP
    
    * :construction: WIP
    
    * Neighbourhood manager (#11)
    
    * :sparkles: GetNextCandidate selection added
    
    * :lock: fixing concurrency issues
    
    * :white_check_mark: testManager improved
    
    * :pencil: removed commented code
    
    * :construction: WIP
    
    * :construction: WIP
    
    * :construction: WIP
    
    * :construction: WIP
    
    * :heavy_check_mark: Make TestAdd pass in neighborhood_test
    
    `Add` should do nothing if the neighborhood list is full.
    
    * :white_check_mark: Improve TestSrvVerifyBoot
    
    * :arrow_up: Upgrade to go 1.13
    
    * :heavy_minus_sign: Use testify instead of magiconair/properties
    
    * :construction:
    
    * :construction: WIP
    
    * :construction: WIP
    
    * :construction: WIP
    
    * :construction: WIP
    
    * Simulation (#14)
    
    * :sparkles: clear rejection filter after refreshing the public salt
    
    * :sparkles: clean rejection filter
    
    * :white_check_mark: Add mpeer test
    
    * :art: gofmt test
    
    * :art: Remove ineffactual assignments
    
    * :hammer: Trigger panic when index is out of bound in deletePeer
    
    * :white_check_mark: Add selection test
    
    * :white_check_mark: Add TestGetFurtherest and TestGetPeerIndex
    
    * :sparkles: both salt updated at the same time and neighborhood dropped
    
    * :art: Add node peering history for simulation
    
    * :construction: WIP
    
    * :sparkles: added sim visualization
    
    * :fire: removed root handler
    
    * :pencil: added README
    
    * :pencil: updated README
    
    * :heavy_minus_sign: removed unused dependencies
    
    * :art: Tidy go.mod
    
    * :construction: Work in progress
    
    * :construction: WIP
    
    * :construction: WIP
    
    * :construction: WIP
    
    * :lipstick: improved start button
    
    * :construction: WIP
    
    * :sparkles: added keyboard support for start
    
    * :construction: WIP
    
    * :construction: WIP
    
    * :construction: WIP
    
    * :construction: WIP
    
    * :construction: WIP
    
    * :construction: WIP
    
    * :sparkles: added input parameters
    
    * :pencil: README updated
    
    * :lipstick: gif updated
    
    * :lipstick: figure updated
    
    * :pencil: updated
    
    * :lipstick: updated gif
    
    * removed simulation metrics
    
    * :pencil: updated
    
    * :pencil: updated
    
    * :recycle: Extract server from discovery and peering
    
    * :bug: Use golang/protobuf
    
    * Update README.md
    
    * :recycle: Rename PeersRequest to DiscoveryRequest
    
    * :pencil2: Fixing typos
    
    * :art: Move unused function to tests
    
    * :recycle: The selection protocol depends on the discovery
    
    * :white_check_mark: Make tests more robust when using -race
    
    * :loud_sound: Improve logging
    
    * :art: Remove unnecessary arguments
    
    * :bug: Fix data races
    
    * :bug: added timeout for simulated network
    
    * :art: added loop to animation
    
    * :recycle: rename neighborhood to selection
    
    * :sparkles: adds initial salt and fixes simulation end
    
    * :pencil: visualizer enabled by default
    
    * :sparkles: new parameter dropAll and improved python script
    
    * :pencil: updated README
    
    * :pencil: updated README
    
    * :bug: fix salt initialization
    
    * :pencil: added blogpost link
    
    * :pencil: Add badges to README
    
    * :construction_worker: Add Travis CI for tests
    
    * :rotating_light: Correct formating
    
    * :construction_worker: Running golangci on Travis
    
    * :rotating_light: Ignore return value of 'logger.Sync'
    
    * :rotating_light: Remove unused functions
    
    * :pencil: Add link to license
    
    * :art: Move simnetwork to transport
    
    * :art: Use the complete network protocol in simulations
    
    * :recycle: Do not export selection/manager
    
    * :fire: Remove gRPC transport layer
    
    * :white_check_mark: Add UDP connection transport test
    
    * :construction: Implement the peer DB using Goshimmer database
    
    * :heavy_plus_sign: Use the local GoShimmer version
    
    * :sparkles: Add support for a persistent database
    
    * :sparkles: Persist private key of local peer in database
    
    * :bug: Set TTL for bootstrap peers
    
    * :construction: Use GoShimmer events
    
    * :sparkles: Store the supported services in the local peer
    
    * :pushpin: Use most current GoShimmer git version as a dep
    
    * :heavy_plus_sign: Switch to hive.go event package
    
    * :art: Use correct module iotaledger/autopeering-sim
    
    * :bug: Provide dummy service in autopeering simulation
    
    * :sparkles: adds service support in the selection
    
    * :sparkles: adds peer discovered events
    
    * :sparkles: adds GetIncomingNeighbors and GetOutgoingNeighbors
    
    * :bug: fixes out of bound error in splitNodeKey
    
    * :sparkles: adds public IP support
    
    * :bug: fixes localhost
    
    * :bug: fixes localhost parsing
    
    * :wrench: changes selection loop to 1s
    
    * :loud_sound: switches from fmt.Println to log.Debug
    
    * :wrench: increases maxKnown to 1000 and always triggers discovered peer
    
    * :sparkles: adds PeerDeleted event
    
    * :construction: moves PeerDeleted event into deletePeer
    
    * :sparkles: adds config paramters for the peer discovery
    
    * :sparkles: adds config parameters to neighbor selection
    
    * :sparkles: enable/disable inbound/outbound selection
    
    * :bulb: Improve Godoc comments
    
    * :sparkles: modifies disabled outbound selection
    
    * :bug: fixes bug with disabling the selection
    
    * :heavy_minus_sign: removes getMyIP() from server
    
    * :mute: removes some debugging logs
    
    * :construction: Introduce services
    
    - Each peer now comes with a set of services
    - Local peer is a proper peer
    - Services are exchanged during Pong and are available for all verified
    peers
    
    * :bug: fixes GetVerifiedPeer
    
    * :sparkles: adds gossip key to the service
    
    * :mute: removes debugging logs
    
    * :white_check_mark: Add test for GetVerifiedPeer
    
    * :bug: Fix main
    
    * :art: Add localNetwork to Protocol
    
    * :bug: Add new but verified peers to the manager
    
    * :wrench: changes configurable parameters
    
    * :bug: fixes DiscoveryRequest field sequence
    
    * :bento: Regenerate proto files
    
    * :art: Cleanup parameters
    
    * :bug: Fix potential race condition
    
    * :mute: Reduce logging verbosity
    
    * :white_check_mark: Add test for selection+discover
    
    * :sparkles: Return net.Addr in Transport
    
    * :bug: Remove inbound/outbound switches completely
    
    * :loud_sound: Improve logging
    
    * :loud_sound: Fix peerdb logs
    
    * :bug: Fix peer updating
    
    * :white_check_mark: Make TestProtFull more robust
    
    * :art: Make queryInterval a parameter
    
    * :loud_sound: Improve loggind during querying
    
    * :bug: Trigger PeerDiscovered only for active peers
    
    * :art: Cleanup protocol tests
    
    * :white_check_mark: Add discovery test on protocol level
    
    * :art: Rename maxVerified to maxManaged
    
    * :wrench: Increase default query interval
    
    * :art: Improve discover benchmarks
    
    * :white_check_mark: Fix manager tests
    
    * :art: Do not use bugged assert.Eventually
    
    * :rotating_light: Fix linter warnings in server
    
    * :rotating_light: Remove unused parameters
    
    * :art: Make transport work on slices of bytes
    
    * :pencil2: Fix typo in comments
    
    * :rotating_light: Fix linter warnings
    
    * :art: UpdateService accepts two strings
    
    * :white_check_mark: Add test that services are received in discover
    
    * :sparkles: adds required services
    
    * :art: Handle closed connections consistently
    
    * :art: Code cleanup
    
    * :bug: fixes DropPeer
    
    * :art: improves debug messages
    
    * :loud_sound: Log errors during reverification
    
    * :loud_sound:
    
     Log packet size
    
    * refactor: remove unused files
    
    * refactor: use internal autopeering package
    
    Co-authored-by: default avatarAngelo Capossele <angelocapossele@gmail.com>
    Co-authored-by: default avatarjkrvivian <jkrvivian@gmail.com>
    8fde09bf
    History
    server_test.go 5.06 KiB
    package server
    
    import (
    	"log"
    	"testing"
    	"time"
    
    	"github.com/iotaledger/goshimmer/packages/autopeering/peer"
    	"github.com/iotaledger/goshimmer/packages/autopeering/salt"
    	"github.com/iotaledger/goshimmer/packages/autopeering/transport"
    	"github.com/stretchr/testify/assert"
    	"github.com/stretchr/testify/mock"
    	"github.com/stretchr/testify/require"
    	"go.uber.org/zap"
    )
    
    const graceTime = 5 * time.Millisecond
    
    var logger *zap.SugaredLogger
    
    func init() {
    	l, err := zap.NewDevelopment()
    	if err != nil {
    		log.Fatalf("cannot initialize logger: %v", err)
    	}
    	logger = l.Sugar()
    }
    
    const (
    	MPing MType = iota
    	MPong
    )
    
    type Message interface {
    	Type() MType
    	Marshal() []byte
    }
    
    type Ping struct{}
    type Pong struct{}
    
    func (m *Ping) Type() MType     { return MPing }
    func (m *Ping) Marshal() []byte { return append([]byte{}, byte(MPing)) }
    
    func (m *Pong) Type() MType     { return MPong }
    func (m *Pong) Marshal() []byte { return append([]byte{}, byte(MPong)) }
    
    func sendPong(args mock.Arguments) {
    	srv := args.Get(0).(*Server)
    	addr := args.Get(1).(string)
    	srv.Send(addr, new(Pong).Marshal())
    }
    
    var (
    	pingMock *mock.Mock
    	pongMock *mock.Mock
    )
    
    func setupTest() func(t *testing.T) {
    	pingMock = new(mock.Mock)
    	pongMock = new(mock.Mock)
    
    	return func(t *testing.T) {
    		pingMock.AssertExpectations(t)
    		pingMock = nil
    		pongMock.AssertExpectations(t)
    		pongMock = nil
    	}
    }
    
    func handle(s *Server, fromAddr string, fromID peer.ID, fromKey peer.PublicKey, data []byte) (bool, error) {
    	msg, err := unmarshal(data)
    	if err != nil {
    		return false, err
    	}
    
    	switch msg.Type() {
    	case MPing:
    		pingMock.Called(s, fromAddr, fromID, fromKey, data)
    
    	case MPong:
    		if s.IsExpectedReply(fromAddr, fromID, MPong, msg) {
    			pongMock.Called(s, fromAddr, fromID, fromKey, data)
    		}
    
    	default:
    		panic("unknown message type")
    	}
    
    	return true, nil
    }
    
    func unmarshal(data []byte) (Message, error) {
    	if len(data) != 1 {
    		return nil, ErrInvalidMessage
    	}
    
    	switch MType(data[0]) {
    	case MPing:
    		return new(Ping), nil
    	case MPong:
    		return new(Pong), nil
    	}
    	return nil, ErrInvalidMessage
    }
    
    func TestSrvEncodeDecodePing(t *testing.T) {
    	// create minimal server just containing the local peer
    	local, err := peer.NewLocal("dummy", "local", peer.NewMemoryDB(logger))
    	require.NoError(t, err)
    	s := &Server{local: local}
    
    	ping := new(Ping)
    	packet := s.encode(ping.Marshal())
    
    	data, key, err := decode(packet)
    	require.NoError(t, err)
    
    	msg, _ := unmarshal(data)
    	assert.Equal(t, local.ID(), key.ID())
    	assert.Equal(t, msg, ping)
    }
    
    func newTestServer(t require.TestingT, name string, trans transport.Transport, logger *zap.SugaredLogger) (*Server, func()) {
    	log := logger.Named(name)
    	db := peer.NewMemoryDB(log.Named("db"))
    	local, err := peer.NewLocal(trans.LocalAddr().Network(), trans.LocalAddr().String(), db)
    	require.NoError(t, err)
    
    	s, _ := salt.NewSalt(100 * time.Second)
    	local.SetPrivateSalt(s)
    	s, _ = salt.NewSalt(100 * time.Second)
    	local.SetPublicSalt(s)
    
    	srv := Listen(local, trans, logger.Named(name), HandlerFunc(handle))
    
    	teardown := func() {
    		srv.Close()
    		db.Close()
    	}
    	return srv, teardown
    }
    
    func sendPing(s *Server, p *peer.Peer) error {
    	ping := new(Ping)
    	isPong := func(msg interface{}) bool {
    		_, ok := msg.(*Pong)
    		return ok
    	}
    
    	errc := s.SendExpectingReply(p.Address(), p.ID(), ping.Marshal(), MPong, isPong)
    	return <-errc
    }
    
    func TestPingPong(t *testing.T) {
    	p2p := transport.P2P()
    
    	srvA, closeA := newTestServer(t, "A", p2p.A, logger)
    	defer closeA()
    	srvB, closeB := newTestServer(t, "B", p2p.B, logger)
    	defer closeB()
    
    	peerA := &srvA.Local().Peer
    	peerB := &srvB.Local().Peer
    
    	t.Run("A->B", func(t *testing.T) {
    		defer setupTest()(t)
    
    		// B expects valid ping from A and sends pong back
    		pingMock.On("handle", srvB, peerA.Address(), peerA.ID(), peerA.PublicKey(), mock.Anything).Run(sendPong).Once()
    		// A expects valid pong from B
    		pongMock.On("handle", srvA, peerB.Address(), peerB.ID(), peerB.PublicKey(), mock.Anything).Once()
    
    		assert.NoError(t, sendPing(srvA, peerB))
    		time.Sleep(graceTime)
    
    	})
    
    	t.Run("B->A", func(t *testing.T) {
    		defer setupTest()(t)
    
    		pingMock.On("handle", srvA, peerB.Address(), peerB.ID(), peerB.PublicKey(), mock.Anything).Run(sendPong).Once() // A expects valid ping from B and sends pong back
    		pongMock.On("handle", srvB, peerA.Address(), peerA.ID(), peerA.PublicKey(), mock.Anything).Once()               // B expects valid pong from A
    
    		assert.NoError(t, sendPing(srvB, peerA))
    		time.Sleep(graceTime)
    	})
    }
    
    func TestSrvPingTimeout(t *testing.T) {
    	defer setupTest()(t)
    
    	p2p := transport.P2P()
    
    	srvA, closeA := newTestServer(t, "A", p2p.A, logger)
    	defer closeA()
    	srvB, closeB := newTestServer(t, "B", p2p.B, logger)
    	closeB()
    
    	peerB := &srvB.Local().Peer
    	assert.EqualError(t, sendPing(srvA, peerB), ErrTimeout.Error())
    }
    
    func TestUnexpectedPong(t *testing.T) {
    	defer setupTest()(t)
    
    	p2p := transport.P2P()
    
    	srvA, closeA := newTestServer(t, "A", p2p.A, logger)
    	defer closeA()
    	srvB, closeB := newTestServer(t, "B", p2p.B, logger)
    	defer closeB()
    
    	// there should never be a Ping.Handle
    	// there should never be a Pong.Handle
    
    	srvA.Send(srvB.LocalAddr(), new(Pong).Marshal())
    }