github.com/supragya/TendermintConnector@v0.0.0-20210619045051-113e32b84fb1/cmd/dataconnect.go (about) 1 /* 2 Copyright © 2020 Supragya Raj <supragyaraj@gmail.com> 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 package cmd 17 18 import ( 19 "fmt" 20 "time" 21 22 log "github.com/sirupsen/logrus" 23 "github.com/spf13/cobra" 24 marlinTypes "github.com/supragya/TendermintConnector/types" 25 26 "github.com/supragya/TendermintConnector/marlin" 27 28 // Tendermint Core Chains 29 "github.com/supragya/TendermintConnector/chains" 30 "github.com/supragya/TendermintConnector/chains/iris" 31 "github.com/supragya/TendermintConnector/chains/cosmos" 32 // "github.com/supragya/TendermintConnector/chains/tm34" 33 ) 34 35 // connectCmd represents the connect command 36 var dataconnectCmd = &cobra.Command{ 37 Use: "dataconnect", 38 Short: "Act as a connector between Marlin Relay and " + compilationChain, 39 Long: `Act as a connector between Marlin Relay and ` + compilationChain, 40 Run: func(cmd *cobra.Command, args []string) { 41 peerAddr := fmt.Sprintf("%v:%v", peerIP, peerPort) 42 rpcAddr := fmt.Sprintf("%v:%v", peerIP, rpcPort) 43 marlinAddr := fmt.Sprintf("%v:%v", marlinIP, marlinPort) 44 45 if keyFile != "" && isConnectionOutgoing { 46 log.Warning("TMCore connector is using a KeyFile to connect to TMCore peer in DIAL mode." + 47 " KeyFiles are useful to connect with peer in LISTEN mode in most use cases since peer would dial a specific peer which connector listens to." + 48 " Configuring KeyFile usage in DIAL mode may lead to unsuccessful connections if peer blacklists connector's ID." + 49 " It is advised that you let connector use anonymous identities if possible.") 50 time.Sleep(3 * time.Second) // Sleep so that warning message is clearly read 51 } 52 53 if isConnectionOutgoing { 54 log.Info("Configuring to DIAL Peer (TMCore) connection address: ", peerAddr, "; rpc address: ", rpcAddr) 55 } else { 56 log.Info("Configuring to LISTEN Peer (TMCore) connection address: ", peerAddr, "; rpc address: ", rpcAddr) 57 } 58 log.Info("Marlin connection address: ", marlinAddr) 59 60 // Channels 61 marlinTo := make(chan marlinTypes.MarlinMessage, 1000) 62 marlinFrom := make(chan marlinTypes.MarlinMessage, 1000) 63 64 // TODO - is this style of invocation correct? can we wrap this? WAITGROUPS??? - v0.1 prerelease 65 go marlin.RunDataConnectHandler(marlinAddr, marlinTo, marlinFrom, direction) 66 67 if doRpcSanity { 68 log.Info("Doing RPC sanity!") 69 nodeStatus, err := getRPCNodeStatus(rpcAddr) 70 if err != nil { 71 return 72 } 73 nodeInfo := extractNodeInfo(nodeStatus) 74 findAndRunDataConnectHandler(nodeInfo["nodeType"].(chains.NodeType), peerAddr, marlinTo, marlinFrom, isConnectionOutgoing, keyFile, listenPortPeer) 75 // } else if compilationChain == "tm34" { 76 // findAndRunDataConnectHandler(tm34.ServicedTMCore, peerAddr, marlinTo, marlinFrom, isConnectionOutgoing, keyFile, listenPortPeer) 77 } else if compilationChain == "iris" { 78 findAndRunDataConnectHandler(iris.ServicedTMCore, peerAddr, marlinTo, marlinFrom, isConnectionOutgoing, keyFile, listenPortPeer) 79 } else if compilationChain == "cosmos" { 80 findAndRunDataConnectHandler(cosmos.ServicedTMCore, peerAddr, marlinTo, marlinFrom, isConnectionOutgoing, keyFile, listenPortPeer) 81 } else { 82 panic("Unknown chain. Exiting") 83 } 84 }, 85 } 86 87 func init() { 88 rootCmd.AddCommand(dataconnectCmd) 89 // if else if compilationChain == "cosmos" { 90 // dataconnectCmd.Flags().StringVarP(&peerIP, "peerip", "i", "127.0.0.1", "Gaia node IP address") 91 // dataconnectCmd.Flags().IntVarP(&peerPort, "peerport", "p", 26656, "Gaia node peer connection port") 92 // dataconnectCmd.Flags().IntVarP(&rpcPort, "rpcport", "r", 26657, "Gaia node rpc port") 93 // dataconnectCmd.Flags().BoolVarP(&doRpcSanity, "rpcsanity", "s", false, "Validate node information prior to connecting to TMCore. (RPC Sanity)") 94 // dataconnectCmd.Flags().StringVarP(&keyFile, "keyfile", "k", "", "KeyFile to use for connection") 95 // dataconnectCmd.Flags().BoolVarP(&isConnectionOutgoing, "dial", "d", false, "Connector DIALs TMCore (gaia node) if flag is set, otherwise connector LISTENs for connections.") 96 // dataconnectCmd.Flags().StringVarP(&marlinIP, "marlinip", "m", "127.0.0.1", "Marlin TCP Bridge IP address") 97 // dataconnectCmd.Flags().IntVarP(&marlinPort, "marlinport", "n", 22401, "Marlin TCP Bridge port") 98 // dataconnectCmd.Flags().StringVarP(&direction, "direction", "e", "both", "Direction of connection [both/producer/consumer]") 99 // dataconnectCmd.Flags().IntVarP(&listenPortPeer, "listenportpeer", "l", 22400, "Port on which Connector should listen for incoming connections from cosmos peer") 100 // } else 101 if compilationChain == "tm34" { 102 dataconnectCmd.Flags().StringVarP(&peerIP, "peerip", "i", "127.0.0.1", "TM34 node IP address") 103 dataconnectCmd.Flags().IntVarP(&peerPort, "peerport", "p", 26656, "TM34 node peer connection port") 104 dataconnectCmd.Flags().IntVarP(&rpcPort, "rpcport", "r", 26657, "TM34 node rpc port") 105 dataconnectCmd.Flags().BoolVarP(&doRpcSanity, "rpcsanity", "s", false, "Validate node information prior to connecting to TMCore. (RPC Sanity)") 106 dataconnectCmd.Flags().StringVarP(&keyFile, "keyfile", "k", "", "KeyFile to use for connection") 107 dataconnectCmd.Flags().BoolVarP(&isConnectionOutgoing, "dial", "d", false, "Connector DIALs TMCore (TM34 node) if flag is set, otherwise connector LISTENs for connections.") 108 dataconnectCmd.Flags().StringVarP(&marlinIP, "marlinip", "m", "127.0.0.1", "Marlin TCP Bridge IP address") 109 dataconnectCmd.Flags().IntVarP(&marlinPort, "marlinport", "n", 22401, "Marlin TCP Bridge port") 110 dataconnectCmd.Flags().StringVarP(&direction, "direction", "e", "producer", "Direction of connection [both/producer/consumer]") 111 dataconnectCmd.Flags().IntVarP(&listenPortPeer, "listenportpeer", "l", 22400, "Port on which Connector should listen for incoming connections from TM34 peer") 112 } else if compilationChain == "iris" { 113 dataconnectCmd.Flags().StringVarP(&peerIP, "peerip", "i", "127.0.0.1", "Iris node IP address") 114 dataconnectCmd.Flags().IntVarP(&peerPort, "peerport", "p", 26656, "Iris node peer connection port") 115 dataconnectCmd.Flags().IntVarP(&rpcPort, "rpcport", "r", 26657, "Iris node rpc port") 116 dataconnectCmd.Flags().BoolVarP(&doRpcSanity, "rpcsanity", "s", false, "Validated node information prior to connecting to TMCore. (RPC Sanity)") 117 dataconnectCmd.Flags().StringVarP(&keyFile, "keyfile", "k", "", "KeyFile to use for connection") 118 dataconnectCmd.Flags().BoolVarP(&isConnectionOutgoing, "dial", "d", false, "Connector DIALs TMCore (iris node) if flag is set, otherwise connector LISTENs for connections.") 119 dataconnectCmd.Flags().StringVarP(&marlinIP, "marlinip", "m", "127.0.0.1", "Marlin TCP Bridge IP address") 120 dataconnectCmd.Flags().IntVarP(&marlinPort, "marlinport", "n", 21901, "Marlin TCP Bridge port") 121 dataconnectCmd.Flags().StringVarP(&direction, "direction", "e", "producer", "Direction of connection [both/producer/consumer]") 122 dataconnectCmd.Flags().IntVarP(&listenPortPeer, "listenportpeer", "l", 21900, "Port on which Connector should listen for incoming connections from iris peer") 123 } else if compilationChain == "cosmos" { 124 dataconnectCmd.Flags().StringVarP(&peerIP, "peerip", "i", "127.0.0.1", "Gaia node IP address") 125 dataconnectCmd.Flags().IntVarP(&peerPort, "peerport", "p", 26656, "Gaia node peer connection port") 126 dataconnectCmd.Flags().IntVarP(&rpcPort, "rpcport", "r", 26657, "Gaia node rpc port") 127 dataconnectCmd.Flags().BoolVarP(&doRpcSanity, "rpcsanity", "s", false, "Validate node information prior to connecting to TMCore. (RPC Sanity)") 128 dataconnectCmd.Flags().StringVarP(&keyFile, "keyfile", "k", "", "KeyFile to use for connection") 129 dataconnectCmd.Flags().BoolVarP(&isConnectionOutgoing, "dial", "d", false, "Connector DIALs TMCore (gaia node) if flag is set, otherwise connector LISTENs for connections.") 130 dataconnectCmd.Flags().StringVarP(&marlinIP, "marlinip", "m", "127.0.0.1", "Marlin TCP Bridge IP address") 131 dataconnectCmd.Flags().IntVarP(&marlinPort, "marlinport", "n", 22401, "Marlin TCP Bridge port") 132 dataconnectCmd.Flags().StringVarP(&direction, "direction", "e", "producer", "Direction of connection [both/producer/consumer]") 133 dataconnectCmd.Flags().IntVarP(&listenPortPeer, "listenportpeer", "l", 22400, "Port on which Connector should listen for incoming connections from cosmos peer") 134 } 135 }