コード例 #1
0
ファイル: tribtest.go プロジェクト: CarterAppleton/p2
func initTribServer(masterServerHostPort string, tribServerPort int) error {
	//	l, err := net.Listen("tcp", tribServerHostPort)
	//	if err != nil {
	//		LOGE.Println("Failed to listen:", err)
	//		return nil, err
	//	}

	tribServerHostPort := net.JoinHostPort("localhost", strconv.Itoa(tribServerPort))
	proxyCounter, err := proxycounter.NewProxyCounter(masterServerHostPort, tribServerHostPort)
	if err != nil {
		LOGE.Println("Failed to setup test:", err)
		return err
	}
	pc = proxyCounter

	rpc.RegisterName("StorageServer", storagerpc.Wrap(pc))
	//rpc.HandleHTTP()
	//go http.Serve(l, nil)

	// Create and start the TribServer.
	tribServer, err := tribserver.NewTribServer(masterServerHostPort, tribServerPort)
	if err != nil {
		LOGE.Println("Failed to create TribServer:", err)
		return err
	}
	ts = tribServer
	//rpc.RegisterName("TribServer", tribrpc.Wrap(ts))
	return nil
}
コード例 #2
0
ファイル: libtest.go プロジェクト: codingfrenzy/p2
// Initialize proxy and libstore
func initLibstore(storage, server, myhostport string, alwaysLease bool) (net.Listener, error) {
	l, err := net.Listen("tcp", server)
	if err != nil {
		LOGE.Println("Failed to listen:", err)
		return nil, err
	}

	// The ProxyServer acts like a "StorageServer" in the system, but also has some
	// additional functionalities that allow us to enforce the number of RPCs made
	// to the storage server, etc.
	proxyCounter, err := proxycounter.NewProxyCounter(storage, server)
	if err != nil {
		LOGE.Println("Failed to setup test:", err)
		return nil, err
	}
	pc = proxyCounter

	// Normally the StorageServer would register itself to receive RPCs,
	// but we don't call NewStorageServer here, do we need to do it here instead.
	rpc.RegisterName("StorageServer", storagerpc.Wrap(pc))

	// Normally the TribServer would call the two methods below when it is first
	// created, but these tests mock out the TribServer all together, so we do
	// it here instead.
	rpc.HandleHTTP()
	go http.Serve(l, nil)

	var leaseMode libstore.LeaseMode
	if alwaysLease {
		leaseMode = libstore.Always
	} else if myhostport == "" {
		leaseMode = libstore.Never
	} else {
		leaseMode = libstore.Normal
	}

	// Create and start the Libstore.
	libstore, err := libstore.NewLibstore(server, myhostport, leaseMode)
	if err != nil {
		LOGE.Println("Failed to create Libstore:", err)
		return nil, err
	}
	ls = libstore
	return l, nil
}
コード例 #3
0
ファイル: tribtest.go プロジェクト: thuhujin/Tribbler
func initTribServer(masterServerHostPort string, tribServerPort int) error {
	tribServerHostPort := net.JoinHostPort("localhost", strconv.Itoa(tribServerPort))
	proxyCounter, err := proxycounter.NewProxyCounter(masterServerHostPort, tribServerHostPort)
	if err != nil {
		LOGE.Println("Failed to setup test:", err)
		return err
	}
	pc = proxyCounter
	rpc.RegisterName("StorageServer", storagerpc.Wrap(pc))

	// Create and start the TribServer.
	tribServer, err := tribserver.NewTribServer(masterServerHostPort, tribServerHostPort)
	if err != nil {
		LOGE.Println("Failed to create TribServer:", err)
		return err
	}
	ts = tribServer
	return nil
}