-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documents to the function (irishandler) #3
base: main
Are you sure you want to change the base?
Changes from 4 commits
697f6ae
ff5c6e3
3b3eef5
105e8f6
6f0715c
977e9da
e4f5f99
32a7e17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,11 @@ var ServicedTMCore chains.NodeType = chains.NodeType{Version: "0.32.2", Network: | |
|
||
// ---------------------- DATA CONNECT INTERFACE -------------------------------- | ||
|
||
|
||
// RunDataConnect checks for errors while making connection with the base. | ||
// This Error may include base connection establishment, creating TM Handler, | ||
// handhsaking, upgrading connection of handshaking. It will also reattempt | ||
// the connection. | ||
func RunDataConnect(peerAddr string, | ||
marlinTo chan marlinTypes.MarlinMessage, | ||
marlinFrom chan marlinTypes.MarlinMessage, | ||
|
@@ -93,6 +98,10 @@ func RunDataConnect(peerAddr string, | |
} | ||
} | ||
|
||
// dialPeer will check if the Peer has dialed succesfully or not, | ||
// This function is used RunDataConnect, if there are errors | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't mention caller |
||
// found while dialling the connection then it will return | ||
// an error to RunDataConnect, otherwise return "nil" | ||
func (h *TendermintHandler) dialPeer() error { | ||
var err error | ||
h.baseConnection, err = net.DialTimeout("tcp", h.peerAddr, 2000*time.Millisecond) | ||
|
@@ -103,6 +112,10 @@ func (h *TendermintHandler) dialPeer() error { | |
return nil | ||
} | ||
|
||
// acceptPeer will check the if the Peer has connected succesfully | ||
// or not, this function is used in RunDataConnect, if there are | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dont mention caller |
||
// errors found while making an successful connection then it will return | ||
// an error to RunDataConnect, otherwise return "nil" | ||
func (h *TendermintHandler) acceptPeer() error { | ||
log.Info("TMCore side listening for dials to ", | ||
string(hex.EncodeToString(h.privateKey.PubKey().Address())), "@<SYSTEM-IP-ADDR>:", h.listenPort) | ||
|
@@ -120,6 +133,10 @@ func (h *TendermintHandler) acceptPeer() error { | |
return nil | ||
} | ||
|
||
// upgradeConnectionAndHandshake checks if there has been a secret | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rephrase. It ESTABLISHES, not CHECKS |
||
// connecton established or if there is a problem with handshaking. | ||
// if no error has been captured, it will give a successful connection | ||
// with Address and node info | ||
func (h *TendermintHandler) upgradeConnectionAndHandshake() error { | ||
var err error | ||
h.secretConnection, err = conn.MakeSecretConnection(h.baseConnection, h.privateKey) | ||
|
@@ -138,6 +155,12 @@ func (h *TendermintHandler) upgradeConnectionAndHandshake() error { | |
return nil | ||
} | ||
|
||
// handshake function follows the protocol set on amino spec, | ||
// MarshalBinaryLengthPrefixed encodes the object according to the Amino spec | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't mention exact amino codec setup. We just need to know that how handshake happens |
||
// same goes for UnmarshalBinaryLengthPrefixedReader | ||
// Error encounterd while seniding handhshaking message or reciving | ||
// using Amino spec will be checked here and | ||
// returned to upgradeConnectionAndHandshake | ||
func (h *TendermintHandler) handshake() error { | ||
var ( | ||
errc = make(chan error, 2) | ||
|
@@ -183,6 +206,8 @@ func (h *TendermintHandler) handshake() error { | |
return nil | ||
} | ||
|
||
// forms a P2P connection with the registered node | ||
// sends and recives routines accordingly | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wrong... it "services" the TM core and not forms the connection... |
||
func (h *TendermintHandler) beginServicing() error { | ||
// Register Messages | ||
RegisterPacket(h.codec) | ||
|
@@ -215,6 +240,13 @@ func (h *TendermintHandler) beginServicing() error { | |
return nil | ||
} | ||
|
||
// Datas are recived by TM Core | ||
// sendRoutine sends PING and PONG message to TM Core | ||
// case h.p2pConnection.pingTimer.C: Sends PING messages to TM Core | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cases are bad in comments, not needed. Mention agenda, not code. |
||
// case h.p2pConnection.pong: Sends PONG messages to TM Core | ||
// case timeout: Check if PONG messages are received in time | ||
// case h.signalShutSend: Block to Shut down sendRoutine | ||
// case marlinmsg: messages are recived from the marlin relay | ||
func (h *TendermintHandler) sendRoutine() { | ||
log.Info("TMCore <- Connector Routine Started") | ||
|
||
|
@@ -394,6 +426,10 @@ func (h *TendermintHandler) sendRoutine() { | |
} | ||
} | ||
|
||
// Data processed and sent back | ||
// case PacketPing: Received PING messages from TM Core | ||
// case PacketPong: Received PONG messages from TM Core | ||
// case PacketMsg: Actual message packets from TM Core (encoded form) | ||
func (h *TendermintHandler) recvRoutine() { | ||
log.Info("TMCore -> Connector Routine Started") | ||
|
||
|
@@ -619,6 +655,7 @@ FOR_LOOP: | |
} | ||
} | ||
|
||
//decodes the Consensus Messages From the Channel Buffer | ||
func (h *TendermintHandler) decodeConsensusMsgFromChannelBuffer(chanbuf []marlinTypes.PacketMsg) (ConsensusMessage, error) { | ||
var databuf []byte | ||
var msg ConsensusMessage | ||
|
@@ -633,6 +670,8 @@ func (h *TendermintHandler) decodeConsensusMsgFromChannelBuffer(chanbuf []marlin | |
return msg, err | ||
} | ||
|
||
// Stop the PONG time when the PING is called upon in | ||
// recvRoutine | ||
func (c *P2PConnection) stopPongTimer() { | ||
if c.pongTimer != nil { | ||
_ = c.pongTimer.Stop() | ||
|
@@ -643,6 +682,8 @@ func (c *P2PConnection) stopPongTimer() { | |
// ---------------------- SPAM FILTER INTERFACE -------------------------------- | ||
|
||
// RunSpamFilter serves as the entry point for a TM Core handler when serving as a spamfilter | ||
// This function also acts as filter at the very begining of the TM Core, spam filter depends | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wrong!. spamfilter is completely different mode. Number of spam filter is wrong. it is number of worker goroutines spawned |
||
// on the Core count. Number of spam filter will be "2* core count". | ||
func RunSpamFilter(rpcAddr string, | ||
marlinTo chan marlinTypes.MarlinMessage, | ||
marlinFrom chan marlinTypes.MarlinMessage) { | ||
|
@@ -670,6 +711,10 @@ func RunSpamFilter(rpcAddr string, | |
handler.throughput.presentThroughput(5, handler.signalShutThroughput) | ||
} | ||
|
||
// Spam Filter executions begins from beginServicingSpamFilter | ||
// this function will check for all possible spam from TM Core. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not from TMCore. Spam is always checked at ingress point of marlin relay |
||
// Spam can also be produced from Marlin Relay. So beginServicingSpamFilter | ||
// will also check for that. | ||
func (h *TendermintHandler) beginServicingSpamFilter(id int) { | ||
log.Info("Running TM side spam filter handler ", id) | ||
// Register Messages | ||
|
@@ -764,6 +809,8 @@ func (h *TendermintHandler) beginServicingSpamFilter(id int) { | |
} | ||
} | ||
|
||
// thoroughMessageCheck is used in beginServicingSpamFilter. | ||
// thoroughMessageCheck verify the Messages from the Marlin Relay | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wrong There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you tell, What would be the correct Statement here! |
||
func (h *TendermintHandler) thoroughMessageCheck(msg ConsensusMessage) bool { | ||
switch msg.(type) { | ||
case *VoteMessage: | ||
|
@@ -791,6 +838,7 @@ func (h *TendermintHandler) thoroughMessageCheck(msg ConsensusMessage) bool { | |
} | ||
} | ||
|
||
// | ||
func (vote *Vote) SignBytes(chainID string, cdc *amino.Codec) []byte { | ||
bz, err := cdc.MarshalBinaryLengthPrefixed(CanonicalizeVote(chainID, vote)) | ||
if err != nil { | ||
|
@@ -799,6 +847,8 @@ func (vote *Vote) SignBytes(chainID string, cdc *amino.Codec) []byte { | |
return bz | ||
} | ||
|
||
// Get the height of block chain | ||
// | ||
func (h *TendermintHandler) getValidators(height int64) ([]Validator, bool) { | ||
if height+10 < h.maxValidHeight { | ||
// Don't service messages too old | ||
|
@@ -853,6 +903,12 @@ func (h *TendermintHandler) getValidators(height int64) ([]Validator, bool) { | |
} | ||
} | ||
|
||
// spamVerdictMessage used in beginServicingSpamFilter. This function | ||
// is used to store Messages of Marlin and even return the Boolean value | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. store messages? it just gives out signal to either allow or deny messages |
||
// in beginServicingSpamFilter, according to boolean value. flow of this | ||
// function gets executed. If the messages are recived in the form of 0x01 | ||
// channel, it will allow the request to be proccessed, otherwise it will | ||
// deny it | ||
func (h *TendermintHandler) spamVerdictMessage(msg marlinTypes.MarlinMessage, allow bool) marlinTypes.MarlinMessage { | ||
if allow { | ||
return marlinTypes.MarlinMessage{ | ||
|
@@ -876,6 +932,7 @@ var isKeyFileUsed, memoized bool | |
var keyFileLocation string | ||
var privateKey ed25519.PrivKeyEd25519 | ||
|
||
//Generates privatekey and publickey | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ED25519 Keypair |
||
func GenerateKeyFile(fileLocation string) { | ||
log.Info("Generating KeyPair for irisnet-0.16.3-mainnet") | ||
|
||
|
@@ -905,6 +962,7 @@ func GenerateKeyFile(fileLocation string) { | |
log.Info("Successfully written keyfile ", fileLocation) | ||
} | ||
|
||
// VerifyKeyFile verify's the 'key' file-location | ||
func VerifyKeyFile(fileLocation string) (bool, error) { | ||
log.Info("Accessing disk to extract info from KeyFile: ", fileLocation) | ||
jsonFile, err := os.Open(fileLocation) | ||
|
@@ -933,6 +991,8 @@ func VerifyKeyFile(fileLocation string) (bool, error) { | |
} | ||
} | ||
|
||
// This functions gets the private key from the keyfile! | ||
// Also verifies the Keyfile integrity | ||
func getPrivateKey() ed25519.PrivKeyEd25519 { | ||
if !isKeyFileUsed { | ||
return ed25519.GenPrivKey() | ||
|
@@ -971,7 +1031,7 @@ func getPrivateKey() ed25519.PrivKeyEd25519 { | |
|
||
// ---------------------- COMMON UTILITIES --------------------------------- | ||
|
||
|
||
//Creates Tendermint Handler between Marlin Relay and TM Core | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. creates between relay and TM core? no really... it just creates a handler object |
||
func createTMHandler(peerAddr string, | ||
rpcAddr string, | ||
marlinTo chan marlinTypes.MarlinMessage, | ||
|
@@ -1016,6 +1076,7 @@ func createTMHandler(peerAddr string, | |
}, nil | ||
} | ||
|
||
//putInfo function into "to", "from", "spam" | ||
func (t *throughPutData) putInfo(direction string, key string, count uint32) { | ||
t.mu.Lock() | ||
switch direction { | ||
|
@@ -1028,7 +1089,8 @@ func (t *throughPutData) putInfo(direction string, key string, count uint32) { | |
} | ||
t.mu.Unlock() | ||
} | ||
|
||
// This function display the logs/stats of marlin to | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not related to marlinTo and marlinFrom actually |
||
// and marlin from or SpamFilter | ||
func (t *throughPutData) presentThroughput(sec time.Duration, shutdownCh chan struct{}) { | ||
for { | ||
time.Sleep(sec * time.Second) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,12 +14,15 @@ import ( | |
"github.com/tendermint/tendermint/crypto/merkle" | ||
) | ||
|
||
// ProtocolVersion defines the structure consisting of P2P, block and App | ||
type ProtocolVersion struct { | ||
P2P uint64 `json:"p2p"` | ||
Block uint64 `json:"block"` | ||
App uint64 `json:"app"` | ||
} | ||
|
||
// DefaultNodeInfo defines the structure consisting of ID, Listener Address, | ||
// Chain/Network ID, Version(Major/Minor), Channels, Moniker | ||
type DefaultNodeInfo struct { | ||
ProtocolVersion ProtocolVersion `json:"protocol_version"` | ||
|
||
|
@@ -43,6 +46,7 @@ type DefaultNodeInfoOther struct { | |
RPCAddress string `json:"rpc_address"` | ||
} | ||
|
||
// P2PConnection defines the structure of P2P Layer | ||
type P2PConnection struct { | ||
conn net.Conn | ||
bufConnReader *bufio.Reader | ||
|
@@ -87,7 +91,8 @@ type P2PConnection struct { | |
type Packet interface { | ||
AssertIsPacket() | ||
} | ||
|
||
// RegisterPacket registers the PING and PONG in the | ||
// form of packet | ||
func RegisterPacket(cdc *amino.Codec) { | ||
cdc.RegisterInterface((*Packet)(nil), nil) | ||
cdc.RegisterConcrete(PacketPing{}, "tendermint/p2p/PacketPing", nil) | ||
|
@@ -99,18 +104,22 @@ func (_ PacketPing) AssertIsPacket() {} | |
func (_ PacketPong) AssertIsPacket() {} | ||
func (_ PacketMsg) AssertIsPacket() {} | ||
|
||
// Structure for Ping Packet | ||
type PacketPing struct { | ||
} | ||
|
||
// Strucutre for Pong Packet | ||
type PacketPong struct { | ||
} | ||
|
||
// Structure for Messages packet | ||
type PacketMsg struct { | ||
ChannelID byte | ||
EOF byte // 1 means message ends here. | ||
Bytes []byte | ||
} | ||
|
||
// String fucntion for Channel ID, Bytes, EOF | ||
func (mp PacketMsg) String() string { | ||
return fmt.Sprintf("PacketMsg{%X:%X T:%X}", mp.ChannelID, mp.Bytes, mp.EOF) | ||
} | ||
|
@@ -120,6 +129,8 @@ type ConsensusMessage interface { | |
ValidateBasic() error | ||
} | ||
|
||
// RegisterConsensusMessages registers the Consensus Messages | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. between tendermint and consensus layer? consensus layer is in tendermint |
||
// between tendermint and consensus layer | ||
func RegisterConsensusMessages(cdc *amino.Codec) { | ||
cdc.RegisterInterface((*ConsensusMessage)(nil), nil) | ||
cdc.RegisterConcrete(&NewRoundStepMessage{}, "tendermint/NewRoundStepMessage", nil) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a library imported from tendermint itself. No need to put commnts support here.