| 176 | } |
| 177 | |
| 178 | func MakeSwitch( |
| 179 | cfg *config.P2PConfig, |
| 180 | i int, |
| 181 | network, version string, |
| 182 | initSwitch func(int, *Switch) *Switch, |
| 183 | opts ...SwitchOption, |
| 184 | ) *Switch { |
| 185 | |
| 186 | nodeKey := NodeKey{ |
| 187 | PrivKey: ed25519.GenPrivKey(), |
| 188 | } |
| 189 | nodeInfo := testNodeInfo(nodeKey.ID(), fmt.Sprintf("node%d", i)) |
| 190 | addr, err := NewNetAddressString( |
| 191 | IDAddressString(nodeKey.ID(), nodeInfo.(DefaultNodeInfo).ListenAddr), |
| 192 | ) |
| 193 | if err != nil { |
| 194 | panic(err) |
| 195 | } |
| 196 | |
| 197 | t := NewMultiplexTransport(nodeInfo, nodeKey, MConnConfig(cfg)) |
| 198 | |
| 199 | if err := t.Listen(*addr); err != nil { |
| 200 | panic(err) |
| 201 | } |
| 202 | |
| 203 | // TODO: let the config be passed in? |
| 204 | sw := initSwitch(i, NewSwitch(cfg, t, opts...)) |
| 205 | sw.SetLogger(log.TestingLogger().With("switch", i)) |
| 206 | sw.SetNodeKey(&nodeKey) |
| 207 | |
| 208 | ni := nodeInfo.(DefaultNodeInfo) |
| 209 | for ch := range sw.reactorsByCh { |
| 210 | ni.Channels = append(ni.Channels, ch) |
| 211 | } |
| 212 | nodeInfo = ni |
| 213 | |
| 214 | // TODO: We need to setup reactors ahead of time so the NodeInfo is properly |
| 215 | // populated and we don't have to do those awkward overrides and setters. |
| 216 | t.nodeInfo = nodeInfo |
| 217 | sw.SetNodeInfo(nodeInfo) |
| 218 | |
| 219 | return sw |
| 220 | } |
| 221 | |
| 222 | func testInboundPeerConn( |
| 223 | conn net.Conn, |