예제 #1
0
// Get a connection to the proxyAppConn addr.
// Check the current hash, and panic if it doesn't match.
func getProxyApp(addr string, hash []byte) (proxyAppConn proxy.AppConn) {
	// use local app (for testing)
	if addr == "local" {
		app := example.NewCounterApplication(true)
		mtx := new(sync.Mutex)
		proxyAppConn = proxy.NewLocalAppConn(mtx, app)
	} else {
		proxyConn, err := Connect(addr)
		if err != nil {
			Exit(Fmt("Failed to connect to proxy for mempool: %v", err))
		}
		remoteApp := proxy.NewRemoteAppConn(proxyConn, 1024)
		remoteApp.Start()

		proxyAppConn = remoteApp
	}

	// Check the hash
	currentHash, err := proxyAppConn.GetHashSync()
	if err != nil {
		PanicCrisis(Fmt("Error in getting proxyAppConn hash: %v", err))
	}
	if !bytes.Equal(hash, currentHash) {
		PanicCrisis(Fmt("ProxyApp hash does not match.  Expected %X, got %X", hash, currentHash))
	}

	return proxyAppConn
}
예제 #2
0
파일: node.go 프로젝트: eris-ltd/tendermint
// Get a connection to the proxyAppConn addr.
// Check the current hash, and panic if it doesn't match.
func GetProxyApp(addr string, hash []byte) (proxyAppConn proxy.AppConn) {
	// use local app (for testing)
	switch addr {
	case "nilapp":
		app := nilapp.NewNilApplication()
		mtx := new(sync.Mutex)
		proxyAppConn = tmspcli.NewLocalClient(mtx, app)
	case "dummy":
		app := dummy.NewDummyApplication()
		mtx := new(sync.Mutex)
		proxyAppConn = tmspcli.NewLocalClient(mtx, app)
	default:
		// Run forever in a loop
		remoteApp, err := proxy.NewRemoteAppConn(addr)
		if err != nil {
			Exit(Fmt("Failed to connect to proxy for mempool: %v", err))
		}
		proxyAppConn = remoteApp
	}

	// Check the hash
	res := proxyAppConn.CommitSync()
	if res.IsErr() {
		PanicCrisis(Fmt("Error in getting proxyAppConn hash: %v", res))
	}
	if !bytes.Equal(hash, res.Data) {
		log.Warn(Fmt("ProxyApp hash does not match.  Expected %X, got %X", hash, res.Data))
	}

	return proxyAppConn
}
예제 #3
0
// Get a connection to the proxyAppConn addr.
// Check the current hash, and panic if it doesn't match.
func getProxyApp(addr string, hash []byte) proxy.AppConn {
	proxyConn, err := Connect(addr)
	if err != nil {
		Exit(Fmt("Failed to connect to proxy for mempool: %v", err))
	}
	proxyAppConn := proxy.NewRemoteAppConn(proxyConn, 1024)

	proxyAppConn.Start()

	// Check the hash
	currentHash, err := proxyAppConn.GetHashSync()
	if err != nil {
		PanicCrisis(Fmt("Error in getting proxyAppConn hash: %v", err))
	}
	if !bytes.Equal(hash, currentHash) {
		PanicCrisis(Fmt("ProxyApp hash does not match.  Expected %X, got %X", hash, currentHash))
	}

	return proxyAppConn
}