예제 #1
0
func addRouteToEstablish(node *mesh.Node, routeConfig RouteConfig) {
	if len(routeConfig.Peers) == 0 {
		return
	}

	addRouteErr := node.AddRoute((domain.RouteID)(routeConfig.RouteID), routeConfig.Peers[0])
	if addRouteErr != nil {
		return
		panic(addRouteErr)
	}
	for peer := 1; peer < len(routeConfig.Peers); peer++ {
		extendErr := node.ExtendRoute((domain.RouteID)(routeConfig.RouteID), routeConfig.Peers[peer], 5*time.Second)
		if extendErr != nil {
			panic(extendErr)
		}
	}
}
예제 #2
0
// Add transport to Node
func AddPeersToNode(node *mesh.Node, config TestConfig) {

	emptyPK := cipher.PubKey{}

	// Connect
	for info, peerToPeer := range config.PeerToPeers {
		if peerToPeer.Peer == emptyPK {
			continue
		}
		addr, port := infoToAddr(info)
		udpConfig := physical.CreateUdp(port, addr)
		udpTransport := physical.CreateNewUDPTransport(udpConfig)
		connectError := udpTransport.ConnectToPeer(peerToPeer.Peer, peerToPeer.Info)
		if connectError != nil {
			panic(connectError)
		}
		transportToPeer := transport.NewTransport(udpTransport, config.TransportConfig)
		node.AddTransport(transportToPeer)
	}
}