當前位置: 首頁>>代碼示例>>Golang>>正文


Golang mesh.PeerNameFromString函數代碼示例

本文整理匯總了Golang中github.com/weaveworks/mesh.PeerNameFromString函數的典型用法代碼示例。如果您正苦於以下問題:Golang PeerNameFromString函數的具體用法?Golang PeerNameFromString怎麽用?Golang PeerNameFromString使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了PeerNameFromString函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: mustPeerName

func mustPeerName() mesh.PeerName {
	peerName, err := mesh.PeerNameFromString(mustHardwareAddr())
	if err != nil {
		panic(err)
	}
	return peerName
}
開發者ID:weaveworks,項目名稱:mesh,代碼行數:7,代碼來源:server.go

示例2: ExpectMessage

func ExpectMessage(alloc *Allocator, dst string, msgType byte, buf []byte) {
	m := alloc.gossip.(*mockGossipComms)
	dstPeerName, _ := mesh.PeerNameFromString(dst)
	m.Lock()
	m.messages = append(m.messages, mockMessage{dstPeerName, msgType, buf})
	m.Unlock()
}
開發者ID:mandubian,項目名稱:weave,代碼行數:7,代碼來源:testutils_test.go

示例3: initMesh

func initMesh(addr, hwaddr, nickname, pw string) *mesh.Router {
	host, portStr, err := net.SplitHostPort(addr)

	if err != nil {
		log.Fatalf("mesh address: %s: %v", addr, err)
	}
	port, err := strconv.Atoi(portStr)
	if err != nil {
		log.Fatalf("mesh address: %s: %v", addr, err)
	}

	name, err := mesh.PeerNameFromString(hwaddr)
	if err != nil {
		log.Fatalf("invalid hardware address %q: %v", hwaddr, err)
	}

	password := []byte(pw)
	if len(password) == 0 {
		// Emtpy password is used to disable secure communication. Using a nil
		// password disables encryption in mesh.
		password = nil
	}

	return mesh.NewRouter(mesh.Config{
		Host:               host,
		Port:               port,
		ProtocolMinVersion: mesh.ProtocolMinVersion,
		Password:           password,
		ConnLimit:          64,
		PeerDiscovery:      true,
		TrustedSubnets:     []*net.IPNet{},
	}, name, nickname, mesh.NullOverlay{}, stdlog.New(ioutil.Discard, "", 0))

}
開發者ID:prometheus,項目名稱:alertmanager,代碼行數:34,代碼來源:main.go

示例4: TestTombstoneDeletion

func TestTombstoneDeletion(t *testing.T) {
	oldNow := now
	defer func() { now = oldNow }()
	now = func() int64 { return 1234 }

	peername, err := mesh.PeerNameFromString("00:00:00:02:00:00")
	require.Nil(t, err)
	nameserver := makeNameserver(peername)

	nameserver.AddEntry("hostname", "containerid", peername, address.Address(0))
	require.Equal(t, []address.Address{0}, nameserver.Lookup("hostname"))

	nameserver.deleteTombstones()
	require.Equal(t, []address.Address{0}, nameserver.Lookup("hostname"))

	nameserver.Delete("hostname", "containerid", "", address.Address(0))
	require.Equal(t, []address.Address{}, nameserver.Lookup("hostname"))
	require.Equal(t, l(Entries{Entry{
		ContainerID: "containerid",
		Origin:      peername,
		Addr:        address.Address(0),
		Hostname:    "hostname",
		Version:     1,
		Tombstone:   1234,
	}}), nameserver.entries)

	now = func() int64 { return 1234 + int64(tombstoneTimeout/time.Second) + 1 }
	nameserver.deleteTombstones()
	require.Equal(t, Entries{}, nameserver.entries)
}
開發者ID:brb,項目名稱:weave,代碼行數:30,代碼來源:nameserver_test.go

示例5: initMesh

func initMesh(addr, hwaddr, nickname string) *mesh.Router {
	host, portStr, err := net.SplitHostPort(addr)

	if err != nil {
		log.Fatalf("mesh address: %s: %v", addr, err)
	}
	port, err := strconv.Atoi(portStr)
	if err != nil {
		log.Fatalf("mesh address: %s: %v", addr, err)
	}

	name, err := mesh.PeerNameFromString(hwaddr)
	if err != nil {
		log.Fatalf("invalid hardware address %q: %v", hwaddr, err)
	}

	return mesh.NewRouter(mesh.Config{
		Host:               host,
		Port:               port,
		ProtocolMinVersion: mesh.ProtocolMinVersion,
		Password:           []byte(""),
		ConnLimit:          64,
		PeerDiscovery:      true,
		TrustedSubnets:     []*net.IPNet{},
	}, name, nickname, mesh.NullOverlay{}, stdlog.New(ioutil.Discard, "", 0))

}
開發者ID:farcaller,項目名稱:alertmanager,代碼行數:27,代碼來源:main.go

示例6: makePeerName

func makePeerName(i int) mesh.PeerName {
	if i >= 10000 {
		panic("makePeerName: invalid value")
	}
	peer, _ := mesh.PeerNameFromString(fmt.Sprintf("%02d:%02d:00:00:00:ff", i/100, i%100))
	return peer
}
開發者ID:brb,項目名稱:weave,代碼行數:7,代碼來源:ring_test.go

示例7: lookupPeername

// Lookup a PeerName by nickname or stringified PeerName.  We can't
// call into the router for this because we are interested in peers
// that have gone away but are still in the ring, which is why we
// maintain our own nicknames map.
func (alloc *Allocator) lookupPeername(name string) (mesh.PeerName, error) {
	for peername, nickname := range alloc.nicknames {
		if nickname == name {
			return peername, nil
		}
	}

	return mesh.PeerNameFromString(name)
}
開發者ID:ybalt,項目名稱:weave,代碼行數:13,代碼來源:allocator.go

示例8: startServer

func startServer(t *testing.T, upstream *dns.ClientConfig) (*DNSServer, *Nameserver, int, int) {
	peername, err := mesh.PeerNameFromString("00:00:00:02:00:00")
	require.Nil(t, err)
	nameserver := New(peername, "", func(mesh.PeerName) bool { return true })
	dnsserver, err := NewDNSServer(nameserver, "weave.local.", "0.0.0.0:0", &mockUpstream{upstream}, 30, 5*time.Second)
	require.Nil(t, err)
	udpPort := dnsserver.servers[0].PacketConn.LocalAddr().(*net.UDPAddr).Port
	tcpPort := dnsserver.servers[1].Listener.Addr().(*net.TCPAddr).Port
	go dnsserver.ActivateAndServe()
	return dnsserver, nameserver, udpPort, tcpPort
}
開發者ID:n054,項目名稱:weave,代碼行數:11,代碼來源:dns_test.go

示例9: makeNetwork

func makeNetwork(size int) ([]*Nameserver, *gossip.TestRouter) {
	gossipRouter := gossip.NewTestRouter(0.0)
	nameservers := make([]*Nameserver, size)

	for i := 0; i < size; i++ {
		name, _ := mesh.PeerNameFromString(fmt.Sprintf("%02d:00:00:02:00:00", i))
		nameserver := makeNameserver(name)
		nameserver.SetGossip(gossipRouter.Connect(nameserver.ourName, nameserver))
		nameserver.Start()
		nameservers[i] = nameserver
	}

	return nameservers, gossipRouter
}
開發者ID:brb,項目名稱:weave,代碼行數:14,代碼來源:nameserver_test.go

示例10: makeAllocator

func makeAllocator(name string, cidrStr string, quorum uint) (*Allocator, address.Range) {
	peername, err := mesh.PeerNameFromString(name)
	if err != nil {
		panic(err)
	}

	_, cidr, err := address.ParseCIDR(cidrStr)
	if err != nil {
		panic(err)
	}

	alloc := NewAllocator(peername, mesh.PeerUID(rand.Int63()),
		"nick-"+name, cidr.Range(), quorum, func(mesh.PeerName) bool { return true })

	return alloc, cidr.HostRange()
}
開發者ID:mandubian,項目名稱:weave,代碼行數:16,代碼來源:testutils_test.go

示例11: TestContainerAndPeerDeath

func TestContainerAndPeerDeath(t *testing.T) {
	peername, err := mesh.PeerNameFromString("00:00:00:02:00:00")
	require.Nil(t, err)
	nameserver := makeNameserver(peername)

	nameserver.AddEntry("hostname", "containerid", peername, address.Address(0))
	require.Equal(t, []address.Address{0}, nameserver.Lookup("hostname"))

	nameserver.ContainerDied("containerid")
	require.Equal(t, []address.Address{}, nameserver.Lookup("hostname"))

	nameserver.AddEntry("hostname", "containerid", peername, address.Address(0))
	require.Equal(t, []address.Address{0}, nameserver.Lookup("hostname"))

	nameserver.PeerGone(peername)
	require.Equal(t, []address.Address{}, nameserver.Lookup("hostname"))
}
開發者ID:brb,項目名稱:weave,代碼行數:17,代碼來源:nameserver_test.go

示例12: TestCtrlTerminates

func TestCtrlTerminates(t *testing.T) {
	var (
		peerName, _  = mesh.PeerNameFromString("01:23:45:67:89:01")
		self         = meshconn.MeshAddr{PeerName: peerName, PeerUID: 123}
		others       = []net.Addr{}
		minPeerCount = 5
		incomingc    = make(chan raftpb.Message)
		outgoingc    = make(chan raftpb.Message, 10000)
		unreachablec = make(chan uint64)
		confchangec  = make(chan raftpb.ConfChange)
		snapshotc    = make(chan raftpb.Snapshot, 10000)
		entryc       = make(chan raftpb.Entry)
		proposalc    = make(chan []byte)
		removedc     = make(chan struct{})
		logger       = log.New(os.Stderr, "", log.LstdFlags)
	)
	c := newCtrl(
		self,
		others,
		minPeerCount,
		incomingc,
		outgoingc,
		unreachablec,
		confchangec,
		snapshotc,
		entryc,
		proposalc,
		removedc,
		logger,
	)
	stopped := make(chan struct{})
	go func() {
		c.stop()
		close(stopped)
	}()
	select {
	case <-stopped:
		t.Log("ctrl terminated")
	case <-time.After(5 * time.Second):
		t.Fatal("ctrl didn't terminate")
	}
}
開發者ID:weaveworks,項目名稱:mesh,代碼行數:42,代碼來源:ctrl_test.go

示例13: checkSuccess

func checkSuccess(t *testing.T, nameStr string, expected uint64) {
	actual, err := mesh.PeerNameFromString(nameStr)
	require.NoError(t, err)
	require.Equal(t, mesh.PeerName(expected), actual)
}
開發者ID:weaveworks,項目名稱:mesh,代碼行數:5,代碼來源:peer_name_mac_test.go

示例14: main

func main() {
	peers := &stringset{}
	var (
		httpListen = flag.String("http", ":8080", "HTTP listen address")
		meshListen = flag.String("mesh", net.JoinHostPort("0.0.0.0", strconv.Itoa(mesh.Port)), "mesh listen address")
		hwaddr     = flag.String("hwaddr", mustHardwareAddr(), "MAC address, i.e. mesh peer ID")
		nickname   = flag.String("nickname", mustHostname(), "peer nickname")
		password   = flag.String("password", "", "password (optional)")
		channel    = flag.String("channel", "default", "gossip channel name")
	)
	flag.Var(peers, "peer", "initial peer (may be repeated)")
	flag.Parse()

	logger := log.New(os.Stderr, *nickname+"> ", log.LstdFlags)

	host, portStr, err := net.SplitHostPort(*meshListen)
	if err != nil {
		logger.Fatalf("mesh address: %s: %v", *meshListen, err)
	}
	port, err := strconv.Atoi(portStr)
	if err != nil {
		logger.Fatalf("mesh address: %s: %v", *meshListen, err)
	}

	name, err := mesh.PeerNameFromString(*hwaddr)
	if err != nil {
		logger.Fatalf("%s: %v", *hwaddr, err)
	}

	router := mesh.NewRouter(mesh.Config{
		Host:               host,
		Port:               port,
		ProtocolMinVersion: mesh.ProtocolMinVersion,
		Password:           []byte(*password),
		ConnLimit:          64,
		PeerDiscovery:      true,
		TrustedSubnets:     []*net.IPNet{},
	}, name, *nickname, mesh.NullOverlay{}, log.New(ioutil.Discard, "", 0))

	peer := newPeer(name, logger)
	gossip := router.NewGossip(*channel, peer)
	peer.register(gossip)

	func() {
		logger.Printf("mesh router starting (%s)", *meshListen)
		router.Start()
	}()
	defer func() {
		logger.Printf("mesh router stopping")
		router.Stop()
	}()

	router.ConnectionMaker.InitiateConnections(peers.slice(), true)

	errs := make(chan error)
	go func() {
		c := make(chan os.Signal)
		signal.Notify(c, syscall.SIGINT)
		errs <- fmt.Errorf("%s", <-c)
	}()
	go func() {
		logger.Printf("HTTP server starting (%s)", *httpListen)
		http.HandleFunc("/", handle(peer))
		errs <- http.ListenAndServe(*httpListen, nil)
	}()
	logger.Print(<-errs)
}
開發者ID:weaveworks,項目名稱:mesh,代碼行數:67,代碼來源:main.go

示例15: main

func main() {
	peers := &stringset{}
	var (
		apiListen  = flag.String("api", ":8080", "API listen address")
		meshListen = flag.String("mesh", net.JoinHostPort("0.0.0.0", strconv.Itoa(mesh.Port)), "mesh listen address")
		hwaddr     = flag.String("hwaddr", mustHardwareAddr(), "MAC address, i.e. mesh peer name")
		nickname   = flag.String("nickname", mustHostname(), "peer nickname")
		password   = flag.String("password", "", "password (optional)")
		channel    = flag.String("channel", "default", "gossip channel name")
		quicktest  = flag.Int("quicktest", 0, "set to integer 1-9 to enable quick test setup of node")
		n          = flag.Int("n", 3, "number of peers expected (lower bound)")
	)
	flag.Var(peers, "peer", "initial peer (may be repeated)")
	flag.Parse()

	if *quicktest >= 1 && *quicktest <= 9 {
		*hwaddr = fmt.Sprintf("00:00:00:00:00:0%d", *quicktest)
		*meshListen = fmt.Sprintf("0.0.0.0:600%d", *quicktest)
		*apiListen = fmt.Sprintf("0.0.0.0:800%d", *quicktest)
		*nickname = fmt.Sprintf("%d", *quicktest)
		for i := 1; i <= 9; i++ {
			peers.Set(fmt.Sprintf("127.0.0.1:600%d", i))
		}
	}

	logger := log.New(os.Stderr, *nickname+"> ", log.LstdFlags)

	host, portStr, err := net.SplitHostPort(*meshListen)
	if err != nil {
		logger.Fatalf("mesh address: %s: %v", *meshListen, err)
	}
	port, err := strconv.Atoi(portStr)
	if err != nil {
		logger.Fatalf("mesh address: %s: %v", *meshListen, err)
	}

	name, err := mesh.PeerNameFromString(*hwaddr)
	if err != nil {
		logger.Fatalf("%s: %v", *hwaddr, err)
	}

	ln, err := net.Listen("tcp", *apiListen)
	if err != nil {
		logger.Fatal(err)
	}

	logger.Printf("hello!")
	defer logger.Printf("goodbye!")

	// Create, but do not start, a router.
	meshLogger := log.New(ioutil.Discard, "", 0) // no log from mesh please
	router := mesh.NewRouter(mesh.Config{
		Host:               host,
		Port:               port,
		ProtocolMinVersion: mesh.ProtocolMinVersion,
		Password:           []byte(*password),
		ConnLimit:          64,
		PeerDiscovery:      true,
		TrustedSubnets:     []*net.IPNet{},
	}, name, *nickname, mesh.NullOverlay{}, meshLogger)

	// Create a meshconn.Peer.
	peer := meshconn.NewPeer(name, router.Ourself.UID, logger)
	gossip := router.NewGossip(*channel, peer)
	peer.Register(gossip)

	// Start the router and join the mesh.
	func() {
		logger.Printf("mesh router starting (%s)", *meshListen)
		router.Start()
	}()
	defer func() {
		logger.Printf("mesh router stopping")
		router.Stop()
	}()

	router.ConnectionMaker.InitiateConnections(peers.slice(), true)

	terminatec := make(chan struct{})
	terminatedc := make(chan error)
	go func() {
		c := make(chan os.Signal)
		signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
		sig := <-c                           // receive interrupt
		close(terminatec)                    // terminate metcd.Server
		<-terminatedc                        // wait for shutdown
		terminatedc <- fmt.Errorf("%s", sig) // forward signal
	}()
	go func() {
		metcdServer := metcd.NewServer(router, peer, *n, terminatec, terminatedc, logger)
		grpcServer := metcd.GRPCServer(metcdServer)
		defer grpcServer.Stop()
		logger.Printf("gRPC listening at %s", *apiListen)
		terminatedc <- grpcServer.Serve(ln)
	}()
	logger.Print(<-terminatedc)
	time.Sleep(time.Second) // TODO(pb): there must be a better way
}
開發者ID:weaveworks,項目名稱:mesh,代碼行數:98,代碼來源:main.go


注:本文中的github.com/weaveworks/mesh.PeerNameFromString函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。