summaryrefslogtreecommitdiff
path: root/agreement/fuzzer/filter_test.go
blob: 64398023870428ad1016d9a24903746a9213cf04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (C) 2019-2024 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// go-algorand 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 Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand.  If not, see <https://www.gnu.org/licenses/>.

package fuzzer

import (
	"github.com/algorand/go-algorand/protocol"
)

// DownstreamFilter is the network filter downsteam filter interface
type DownstreamFilter interface {
	SendMessage(sourceNode, targetNode int, tag protocol.Tag, data []byte)
	GetDownstreamFilter() DownstreamFilter
}

// UpstreamFilter is the network filter upstream filter interface
type UpstreamFilter interface {
	ReceiveMessage(sourceNode int, tag protocol.Tag, data []byte)
	Tick(newClockTime int) bool // return true if a network operartion might be due; i.e. closed channel, sent message, etc.
}

// NetworkFilter is a single filter interface
type NetworkFilter interface {
	DownstreamFilter
	UpstreamFilter
	SetDownstreamFilter(f DownstreamFilter)
	SetUpstreamFilter(f UpstreamFilter)
}

type ShutdownFilter interface {
	PreShutdown()
	PostShutdown()
}

// NetworkFilterFactory interface used to create new network filters.
type NetworkFilterFactory interface {
	CreateFilter(nodeID int, fuzzer *Fuzzer) NetworkFilter
	Unmarshal([]byte) NetworkFilterFactory
}

var registeredFilterFactories = []NetworkFilterFactory{}