mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-10-14 00:59:33 +00:00
[NOD-1117] Write interfaces for P2P layer (#784)
* [NOD-1117] Write interfaces for P2P layer * [NOD-1117] Add logs
This commit is contained in:
parent
749775c7ea
commit
580e37943b
@ -46,6 +46,9 @@ var (
|
|||||||
txmpLog = BackendLog.Logger("TXMP")
|
txmpLog = BackendLog.Logger("TXMP")
|
||||||
utilLog = BackendLog.Logger("UTIL")
|
utilLog = BackendLog.Logger("UTIL")
|
||||||
profLog = BackendLog.Logger("PROF")
|
profLog = BackendLog.Logger("PROF")
|
||||||
|
protLog = BackendLog.Logger("PROT")
|
||||||
|
muxxLog = BackendLog.Logger("MUXX")
|
||||||
|
p2psLog = BackendLog.Logger("P2PS")
|
||||||
)
|
)
|
||||||
|
|
||||||
// SubsystemTags is an enum of all sub system tags
|
// SubsystemTags is an enum of all sub system tags
|
||||||
@ -67,7 +70,10 @@ var SubsystemTags = struct {
|
|||||||
SYNC,
|
SYNC,
|
||||||
TXMP,
|
TXMP,
|
||||||
UTIL,
|
UTIL,
|
||||||
PROF string
|
PROF,
|
||||||
|
PROT,
|
||||||
|
MUXX,
|
||||||
|
P2PS string
|
||||||
}{
|
}{
|
||||||
ADXR: "ADXR",
|
ADXR: "ADXR",
|
||||||
AMGR: "AMGR",
|
AMGR: "AMGR",
|
||||||
@ -87,6 +93,9 @@ var SubsystemTags = struct {
|
|||||||
TXMP: "TXMP",
|
TXMP: "TXMP",
|
||||||
UTIL: "UTIL",
|
UTIL: "UTIL",
|
||||||
PROF: "PROF",
|
PROF: "PROF",
|
||||||
|
PROT: "PROT",
|
||||||
|
MUXX: "MUXX",
|
||||||
|
P2PS: "P2PS",
|
||||||
}
|
}
|
||||||
|
|
||||||
// subsystemLoggers maps each subsystem identifier to its associated logger.
|
// subsystemLoggers maps each subsystem identifier to its associated logger.
|
||||||
@ -109,6 +118,9 @@ var subsystemLoggers = map[string]*logs.Logger{
|
|||||||
SubsystemTags.TXMP: txmpLog,
|
SubsystemTags.TXMP: txmpLog,
|
||||||
SubsystemTags.UTIL: utilLog,
|
SubsystemTags.UTIL: utilLog,
|
||||||
SubsystemTags.PROF: profLog,
|
SubsystemTags.PROF: profLog,
|
||||||
|
SubsystemTags.PROT: protLog,
|
||||||
|
SubsystemTags.MUXX: muxxLog,
|
||||||
|
SubsystemTags.P2PS: p2psLog,
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitLog attaches log file and error log file to the backend log.
|
// InitLog attaches log file and error log file to the backend log.
|
||||||
|
8
messagemux/messagemux.go
Normal file
8
messagemux/messagemux.go
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package messagemux
|
||||||
|
|
||||||
|
import "github.com/kaspanet/kaspad/wire"
|
||||||
|
|
||||||
|
// Mux represents a p2p message multiplexer.
|
||||||
|
type Mux interface {
|
||||||
|
AddFlow(msgTypes []string, ch chan<- wire.Message)
|
||||||
|
}
|
16
p2pserver/p2pserver.go
Normal file
16
p2pserver/p2pserver.go
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package p2pserver
|
||||||
|
|
||||||
|
import "github.com/kaspanet/kaspad/wire"
|
||||||
|
|
||||||
|
// Server represents a p2p server.
|
||||||
|
type Server interface {
|
||||||
|
Connect(address string) (Connection, error)
|
||||||
|
Connections() []Connection
|
||||||
|
}
|
||||||
|
|
||||||
|
// Connection represents a p2p server connection.
|
||||||
|
type Connection interface {
|
||||||
|
Send(message wire.Message) error
|
||||||
|
Receive() (wire.Message, error)
|
||||||
|
Disconnect() error
|
||||||
|
}
|
9
protocol/log.go
Normal file
9
protocol/log.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package protocol
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/kaspanet/kaspad/logger"
|
||||||
|
"github.com/kaspanet/kaspad/util/panics"
|
||||||
|
)
|
||||||
|
|
||||||
|
var log, _ = logger.Get(logger.SubsystemTags.PROT)
|
||||||
|
var spawn = panics.GoroutineWrapperFunc(log)
|
24
protocol/protocol.go
Normal file
24
protocol/protocol.go
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package protocol
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/kaspanet/kaspad/blockdag"
|
||||||
|
"github.com/kaspanet/kaspad/messagemux"
|
||||||
|
"github.com/kaspanet/kaspad/p2pserver"
|
||||||
|
"github.com/kaspanet/kaspad/wire"
|
||||||
|
)
|
||||||
|
|
||||||
|
// StartProtocol starts the p2p protocol for a given connection
|
||||||
|
func StartProtocol(server p2pserver.Server, mux messagemux.Mux, connection p2pserver.Connection,
|
||||||
|
dag *blockdag.BlockDAG) {
|
||||||
|
|
||||||
|
mux.AddFlow([]string{wire.CmdTx}, startDummy(server, connection, dag))
|
||||||
|
}
|
||||||
|
|
||||||
|
func startDummy(server p2pserver.Server, connection p2pserver.Connection, dag *blockdag.BlockDAG) chan<- wire.Message {
|
||||||
|
ch := make(chan wire.Message)
|
||||||
|
spawn(func() {
|
||||||
|
for range ch {
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return ch
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user