コード例 #1
0
ファイル: tribserver_impl.go プロジェクト: oldady/ds_p2
// NewTribServer creates, starts and returns a new TribServer. masterServerHostPort
// is the master storage server's host:port and port is this port number on which
// the TribServer should listen. A non-nil error should be returned if the TribServer
// could not be started.
//
// For hints on how to properly setup RPC, see the rpc/tribrpc package.
func NewTribServer(masterServerHostPort, myHostPort string) (TribServer, error) {
	newStore, err := libstore.NewLibstore(masterServerHostPort, myHostPort, libstore.Never)
	if err != nil {
		return nil, err
	}

	ts := &tribServer{
		myHostPort: myHostPort,
		Libstore:   newStore,
	}

	err = rpc.RegisterName("TribServer", tribrpc.Wrap(ts))
	if err != nil {
		return nil, err
	}

	rpc.HandleHTTP()
	l, err := net.Listen("tcp", myHostPort)
	if err != nil {
		return nil, err
	}
	go http.Serve(l, nil)

	return ts, nil
}
コード例 #2
0
// NewTribServer creates, starts and returns a new TribServer. masterServerHostPort
// is the master storage server's host:port and port is this port number on which
// the TribServer should listen. A non-nil error should be returned if the TribServer
// could not be started.
//
// For hints on how to properly setup RPC, see the rpc/tribrpc package.
func NewTribServer(masterServerHostPort, myHostPort string) (TribServer, error) {
	libStore, err := libstore.NewLibstore(masterServerHostPort, myHostPort, libstore.Never)
	//fmt.Println("Creating new tribServer...")
	if err != nil {
		return nil, err
	}

	var tribServ tribServer = tribServer{
		libStore: libStore,
	}
	l, err2 := net.Listen("tcp", myHostPort)
	if err2 != nil {
		fmt.Println(err2)
		return nil, err2
	}
	//go http.Serve(l, nil)
	err1 := rpc.RegisterName("TribServer", tribrpc.Wrap(&tribServ))
	if err1 != nil {
		fmt.Println(err1)
		return nil, err1
	}
	rpc.HandleHTTP()
	go http.Serve(l, nil)

	return &tribServ, nil
}
コード例 #3
0
ファイル: tribserver_impl.go プロジェクト: oldady/Tribbler
// NewTribServer creates, starts and returns a new TribServer. masterServerHostPort
// is the master storage server's host:port and port is this port number on which
// the TribServer should listen. A non-nil error should be returned if the TribServer
// could not be started.
//
// For hints on how to properly setup RPC, see the rpc/tribrpc package.
func NewTribServer(masterServerHostPort, myHostPort string) (TribServer, error) {
	fmt.Println("tribserver being connection!")
	server := new(tribServer)
	lib, err := libstore.NewLibstore(masterServerHostPort, myHostPort, libstore.Normal)
	if err != nil {
		fmt.Println("failed to connect!")
		//fmt.Println(err)
		return nil, err
	}

	server.lib = lib
	server.id = 0
	server.hostport = myHostPort

	// listen for incoming RPC
	listener, err := net.Listen("tcp", myHostPort)
	if err != nil {
		fmt.Println("Listen error!")
		return nil, err
	}

	// warp the tribserver
	err = rpc.RegisterName("TribServer", tribrpc.Wrap(server))
	if err != nil {
		fmt.Println("RegisterName error!")
		return nil, err
	}

	rpc.HandleHTTP()
	go http.Serve(listener, nil)

	fmt.Println("server started!!!!!!!")
	return server, nil
}
コード例 #4
0
ファイル: tribserver_impl.go プロジェクト: jbuckman/p2-440
// NewTribServer creates, starts and returns a new TribServer. masterServerHostPort
// is the master storage server's host:port and port is this port number on which
// the TribServer should listen. A non-nil error should be returned if the TribServer
// could not be started.
//
// For hints on how to properly setup RPC, see the rpc/tribrpc package.
func NewTribServer(masterServerHostPort, myHostPort string) (TribServer, error) {
	tribServer := new(tribServer)

	// Create the server socket that will listen for incoming RPCs.
	listener, err := net.Listen("tcp", myHostPort)
	if err != nil {
		return nil, err
	}

	// Wrap the tribServer before registering it for RPC.
	err = rpc.RegisterName("TribServer", tribrpc.Wrap(tribServer))
	if err != nil {
		return nil, err
	}

	// Setup the HTTP handler that will server incoming RPCs and
	// serve requests in a background goroutine.
	rpc.HandleHTTP()
	go http.Serve(listener, nil)

	storage, err := libstore.NewLibstore(masterServerHostPort, myHostPort, libstore.Never)
	if err != nil {
		return nil, err
	}

	tribServer.storage = storage

	return tribServer, nil
}
コード例 #5
0
// NewTribServer creates, starts and returns a new TribServer. masterServerHostPort
// is the master storage server's host:port and port is this port number on which
// the TribServer should listen. A non-nil error should be returned if the TribServer
// could not be started.
//
// For hints on how to properly setup RPC, see the rpc/tribrpc package.
func NewTribServer(masterServerHostPort, myHostPort string) (TribServer, error) {

	tribServer := &tribServer{}

	var newError error
	tribServer.libstore, newError = libstore.NewLibstore(masterServerHostPort, myHostPort, libstore.Normal)
	if newError != nil {
		fmt.Println(newError)
	}

	err := rpc.RegisterName("TribServer", tribrpc.Wrap(tribServer))
	if err != nil {
		return nil, err
	}
	rpc.HandleHTTP()
	listener, err := net.Listen("tcp", ":"+strings.Split(myHostPort, ":")[1])
	if err != nil {
		return nil, err
	}

	go http.Serve(listener, nil)

	fmt.Println("TribServer Created!", myHostPort)
	return tribServer, nil
}
コード例 #6
0
// NewTribServer creates, starts and returns a new TribServer. masterServerHostPort
// is the master storage server's host:port and port is this port number on which
// the TribServer should listen. A non-nil error should be returned if the TribServer
// could not be started.
//
// For hints on how to properly setup RPC, see the rpc/tribrpc package.
func NewTribServer(masterServerHostPort, myHostPort string) (TribServer, error) {
	LOGE.Printf("NewTribServer:: masterServerHostPort=%s myHostPort=%s\n", masterServerHostPort, myHostPort)
	server := new(tribServer)
	server.hostPort = myHostPort
	server.index = 0
	lib, err := libstore.NewLibstore(masterServerHostPort, myHostPort, libstore.Normal)
	if err != nil {
		return nil, err
	}
	server.lib = lib

	listener, err := net.Listen("tcp", myHostPort)
	if err != nil {
		return nil, err
	}

	err = rpc.RegisterName("TribServer", tribrpc.Wrap(server))
	if err != nil {
		fmt.Println("RegisterName error!")
		return nil, err
	}

	rpc.HandleHTTP()
	go http.Serve(listener, nil)

	return server, nil
}
コード例 #7
0
ファイル: tribserver_impl.go プロジェクト: pyurky/p2
// NewTribServer creates, starts and returns a new TribServer. masterServerHostPort
// is the master storage server's host:port and port is this port number on which
// the TribServer should listen. A non-nil error should be returned if the TribServer
// could not be started.
//
// For hints on how to properly setup RPC, see the rpc/tribrpc package.
func NewTribServer(masterServerHostPort, myHostPort string) (TribServer, error) {

	ts := new(tribServer)

	// Create the libstore for this server
	ls, err := libstore.NewLibstore(masterServerHostPort, myHostPort, libstore.Never)
	if err != nil {
		fmt.Println("Failed to create libstore")
		return nil, errors.New("Couldn't start libstore for Tribserver")
	}
	ts.ls = ls

	// Start listening for connections from TribClients
	rpc.RegisterName("TribServer", tribrpc.Wrap(ts))
	rpc.HandleHTTP()
	l, e := net.Listen("tcp", myHostPort)
	if e != nil {
		fmt.Println("Failed to listen with Tribserver")
		return nil, errors.New("Tribserver couldn't start listening")
	}
	go http.Serve(l, nil)
	return ts, nil

	// Get rid of this.  I didn't want to keep commenting out fmt for testing when I didn't use it
	fmt.Println("this is here so I don't throw an error for not using fmt")
	return nil, nil
}
コード例 #8
0
// NewTribServer creates, starts and returns a new TribServer. masterServerHostPort
// is the master storage server's host:port and port is this port number on which
// the TribServer should listen. A non-nil error should be returned if the TribServer
// could not be started.
//
// For hints on how to properly setup RPC, see the rpc/tribrpc package.
func NewTribServer(masterServerHostPort, myHostPort string) (TribServer, error) {
	tribServer := new(tribServer)
	ls, err := libstore.NewLibstore(masterServerHostPort, myHostPort, libstore.Normal)
	if err != nil {
		return nil, errors.New("Libstore failed.")
	}

	tribServer.lib_store = ls

	// Create the server socket that will listen for incoming RPCs.
	_, port, _ := net.SplitHostPort(myHostPort)
	listener, err := net.Listen("tcp", fmt.Sprintf(":%s", port))
	if err != nil {
		return nil, err
	}

	// Wrap the tribServer before registering it for RPC.
	err = rpc.RegisterName("TribServer", tribrpc.Wrap(tribServer))
	if err != nil {
		return nil, err
	}

	// Setup the HTTP handler that will server incoming RPCs and
	// serve requests in a background goroutine.
	rpc.HandleHTTP()
	go http.Serve(listener, nil)

	return tribServer, nil
	// return nil, errors.New("not implemented")
}
コード例 #9
0
ファイル: tribserver_impl.go プロジェクト: thuhujin/Tribbler
// NewTribServer creates, starts and returns a new TribServer. masterServerHostPort
// is the master storage server's host:port and port is this port number on which
// the TribServer should listen. A non-nil error should be returned if the TribServer
// could not be started.
//
// For hints on how to properly setup RPC, see the rpc/tribrpc package.
func NewTribServer(masterServerHostPort, myHostPort string) (TribServer, error) {
	ls, err := libstore.NewLibstore(masterServerHostPort, myHostPort, libstore.Normal)
	if err != nil {
		return nil, err
	}
	ts := new(tribServer)
	ts.ls = ls
	listener, err := net.Listen("tcp", myHostPort)
	if err != nil {
		return nil, err
	}
	// Wrap the tribServer before registering it for RPC.
	err = rpc.RegisterName("TribServer", tribrpc.Wrap(ts))
	if err != nil {
		return nil, err
	}
	// Setup the HTTP handler that will server incoming RPCs and
	// serve requests in a background goroutine.
	rpc.HandleHTTP()
	go http.Serve(listener, nil)

	return ts, nil
}
コード例 #10
0
// NewTribServer creates, starts and returns a new TribServer. masterServerHostPort
// is the master storage server's host:port and port is this port number on which
// the TribServer should listen. A non-nil error should be returned if the TribServer
// could not be started.
//
// For hints on how to properly setup RPC, see the rpc/tribrpc package.
func NewTribServer(masterServerHostPort, myHostPort string) (TribServer, error) {
	libstore, err := libstore.NewLibstore(masterServerHostPort, myHostPort, libstore.Never)
	if err != nil {
		return nil, errors.New("Creating new libstore failed")
	}
	newTribServer := &tribServer{
		ls: libstore,
	}

	listener, err := net.Listen("tcp", myHostPort)
	if err != nil {
		return nil, err
	}

	err = rpc.RegisterName("TribServer", tribrpc.Wrap(newTribServer))
	if err != nil {
		return nil, err
	}
	rpc.HandleHTTP()
	go http.Serve(listener, nil)

	return newTribServer, nil
}