Пример #1
0
func closePeerInternal(peer Peer, force bool) error {
	if peer == nil {
		return utils.ErrNilArgument
	}

	name := peer.GetName()
	log.Info("Closing peer [%s]...", name)
	entry, ok := peers[name]
	if !ok {
		return utils.ErrInvalidReference
	}
	if entry.counter == 1 || force {
		defer delete(peers, name)
		err := peers[name].peer.(*peerImpl).close()
		log.Info("Closing peer [%s]...done! [%s].", name, utils.ErrToString(err))

		return err
	}

	// decrease counter
	entry.counter--
	peers[name] = entry
	log.Info("Closing peer [%s]...decreased counter at [%d].", name, peers[name].counter)

	return nil
}
Пример #2
0
func closeClientInternal(client Client, force bool) error {
	if client == nil {
		return utils.ErrNilArgument
	}

	name := client.GetName()
	log.Info("Closing client [%s]...", name)
	entry, ok := clients[name]
	if !ok {
		return utils.ErrInvalidReference
	}
	if entry.counter == 1 || force {
		defer delete(clients, name)
		err := clients[name].client.(*clientImpl).close()
		log.Debug("Closing client [%s]...cleanup! [%s].", name, utils.ErrToString(err))

		return err
	}

	// decrease counter
	entry.counter--
	clients[name] = entry
	log.Debug("Closing client [%s]...decreased counter at [%d].", name, clients[name].counter)

	return nil
}
Пример #3
0
func closePeerInternal(peer Peer) error {
	id := peer.GetName()
	log.Info("Closing peer [%s]...", id)
	if _, ok := peers[id]; !ok {
		return utils.ErrInvalidReference
	}
	defer delete(peers, id)

	err := peers[id].(*peerImpl).close()

	log.Info("Closing peer [%s]...done! [%s].", id, utils.ErrToString(err))

	return err
}
Пример #4
0
func closeValidatorInternal(peer Peer) error {
	name := peer.GetName()
	log.Info("Closing validator [%s]...", name)
	if _, ok := validators[name]; !ok {
		return utils.ErrInvalidReference
	}
	defer delete(validators, name)

	err := validators[name].(*validatorImpl).close()

	log.Info("Closing validator [%s]...done! [%s].", name, utils.ErrToString(err))

	return err
}
Пример #5
0
func closeClientInternal(client Client) error {
	name := client.GetName()
	log.Info("Closing client [%s]...", name)
	if _, ok := clients[name]; !ok {
		return utils.ErrInvalidReference
	}
	defer delete(clients, name)

	err := clients[name].(*clientImpl).close()

	log.Info("Closing client [%s]...done! [%s].", name, utils.ErrToString(err))

	return err
}
Пример #6
0
func (ks *keyStore) createKeyStoreIfKeyStorePathEmpty() error {
	// Check directory
	ksPath := ks.conf.getKeyStorePath()
	missing, err := utils.DirMissingOrEmpty(ksPath)
	ks.log.Debug("Keystore path [%s] missing [%t]: [%s]", ksPath, missing, utils.ErrToString(err))

	if !missing {
		// Check file
		missing, err = utils.FileMissing(ks.conf.getKeyStorePath(), ks.conf.getKeyStoreFilename())
		ks.log.Debug("Keystore file [%s] missing [%t]:[%s]", ks.conf.getKeyStoreFilePath(), missing, utils.ErrToString(err))
	}

	if missing {
		err := ks.createKeyStore()
		if err != nil {
			ks.log.Debug("Failed creating db At [%s]: ", ks.conf.getKeyStoreFilePath(), err.Error())
			return nil
		}
	}

	return nil
}