• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang objects.Hash类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中emp/objects.Hash的典型用法代码示例。如果您正苦于以下问题:Golang Hash类的具体用法?Golang Hash怎么用?Golang Hash使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Hash类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: GetPubkey

// Get Encrypted Public Key from database.
func GetPubkey(log chan string, addrHash objects.Hash) *objects.EncryptedPubkey {
	mutex.Lock()
	defer mutex.Unlock()

	hash := addrHash.GetBytes()

	if hashList == nil || dbConn == nil {
		return nil
	}
	if hashList[string(hash)] != PUBKEY {
		return nil
	}

	for s, err := dbConn.Query("SELECT payload FROM pubkey WHERE hash=?", hash); err == nil; err = s.Next() {
		var payload []byte
		s.Scan(&payload) // Assigns 1st column to rowid, the rest to row
		pub := new(objects.EncryptedPubkey)
		pub.AddrHash = addrHash
		copy(pub.IV[:], payload[:16])
		pub.Payload = payload[16:]
		return pub
	}
	// Not Found
	return nil
}
开发者ID:dcposch,项目名称:emp,代码行数:26,代码来源:objects.go


示例2: AddPurge

// Add Purge Token to database, and remove corresponding message if necessary.
func AddPurge(log chan string, p objects.Purge) error {
	mutex.Lock()
	defer mutex.Unlock()

	txid := p.GetBytes()
	hashArr := sha512.Sum384(txid)
	hash := hashArr[:]

	if hashList == nil || dbConn == nil {
		return DBError(EUNINIT)
	}
	hashObj := new(objects.Hash)
	hashObj.FromBytes(hash)

	if Contains(*hashObj) == PURGE {
		return nil
	}

	err := dbConn.Exec("INSERT INTO purge VALUES (?, ?)", hash, txid)
	if err != nil {
		log <- fmt.Sprintf("Error inserting purge into db... %s", err)
		return err
	}

	Add(*hashObj, PURGE)
	return nil
}
开发者ID:dcposch,项目名称:emp,代码行数:28,代码来源:objects.go


示例3: RemoveHash

// Remove any object from the database and hash list.
func RemoveHash(log chan string, hashObj objects.Hash) error {
	mutex.Lock()
	defer mutex.Unlock()

	hash := hashObj.GetBytes()

	if hashList == nil || dbConn == nil {
		return DBError(EUNINIT)
	}

	var sql string

	switch Contains(hashObj) {
	case PUBKEY:
		sql = "DELETE FROM pubkey WHERE hash=?"
	case MSG:
		sql = "DELETE FROM msg WHERE hash=?"
	case PURGE:
		sql = "DELETE FROM purge WHERE hash=?"
	default:
		return nil
	}

	err := dbConn.Exec(sql, hash)
	if err != nil {
		log <- fmt.Sprintf("Error deleting hash from db... %s", err)
		return nil
	}

	Delete(hashObj)
	return nil
}
开发者ID:dcposch,项目名称:emp,代码行数:33,代码来源:objects.go


示例4: GetMessage

// Get basic message from database.
func GetMessage(log chan string, txidHash objects.Hash) *objects.Message {
	mutex.Lock()
	defer mutex.Unlock()

	hash := txidHash.GetBytes()

	if hashList == nil || dbConn == nil {
		return nil
	}
	if hashList[string(hash)] != MSG && hashList[string(hash)] != PUB {
		return nil
	}

	msg := new(objects.Message)

	for s, err := dbConn.Query("SELECT * FROM msg WHERE hash=?", hash); err == nil; err = s.Next() {
		var timestamp int64
		encrypted := make([]byte, 0, 0)
		txidhash := make([]byte, 0, 0)
		addrhash := make([]byte, 0, 0)
		s.Scan(&txidhash, &addrhash, &timestamp, &encrypted)

		msg.TxidHash.FromBytes(txidhash)
		msg.AddrHash.FromBytes(addrhash)
		msg.Timestamp = time.Unix(timestamp, 0)
		msg.Content.FromBytes(encrypted)

		return msg
	}
	// Not Found
	return nil
}
开发者ID:dcposch,项目名称:emp,代码行数:33,代码来源:objects.go


示例5: DeleteAddress

func DeleteAddress(addrHash *objects.Hash) error {
	localMutex.Lock()
	defer localMutex.Unlock()

	if Contains(*addrHash) > ADDRESS {
		return errors.New("Error Deleting Message: Not Found!")
	}

	return LocalDB.Exec("DELETE FROM addressbook WHERE hash=?", addrHash.GetBytes())
}
开发者ID:dcposch,项目名称:emp,代码行数:10,代码来源:dbAdmin.go


示例6: DeleteMessage

func DeleteMessage(txidHash *objects.Hash) error {
	localMutex.Lock()
	defer localMutex.Unlock()

	if Contains(*txidHash) > SENDBOX {
		return errors.New("Error Deleting Message: Not Found!")
	}

	return LocalDB.Exec("DELETE FROM msg WHERE txid_hash=?", txidHash.GetBytes())
}
开发者ID:dcposch,项目名称:emp,代码行数:10,代码来源:dbAdmin.go


示例7: Contains

// Get type of object in Hash List
func Contains(hashObj objects.Hash) int {
	hash := string(hashObj.GetBytes())
	if hashList != nil {
		hashType, ok := hashList[hash]
		if ok {
			return hashType
		} else {
			return NOTFOUND
		}
	}
	return NOTFOUND
}
开发者ID:dcposch,项目名称:emp,代码行数:13,代码来源:localdb.go


示例8: ObjList

// List of all hashes in the hash list.
func ObjList() *objects.Obj {
	if hashList == nil {
		return nil
	}

	ret := new(objects.Obj)
	ret.HashList = make([]objects.Hash, 0, 0)

	hash := new(objects.Hash)

	for key, _ := range hashList {
		hash.FromBytes([]byte(key))
		ret.HashList = append(ret.HashList, *hash)
	}
	return ret
}
开发者ID:dcposch,项目名称:emp,代码行数:17,代码来源:hashlist.go


示例9: GetEncrypted

func (service *EMPService) GetEncrypted(r *http.Request, args *[]byte, reply *encryption.EncryptedMessage) error {
	if !basicAuth(service.Config, r) {
		service.Config.Log <- fmt.Sprintf("Unauthorized RPC Request from: %s", r.RemoteAddr)
		return errors.New("Unauthorized")
	}

	var txidHash objects.Hash
	txidHash.FromBytes(*args)

	// Get Message from Database
	msg, err := localdb.GetMessageDetail(txidHash)
	if err != nil {
		return err
	}

	*reply = *msg.Encrypted
	return nil
}
开发者ID:dcposch,项目名称:emp,代码行数:18,代码来源:rpcmsg.go


示例10: GetMessageDetail

func GetMessageDetail(txidHash objects.Hash) (*objects.FullMessage, error) {
	localMutex.Lock()
	defer localMutex.Unlock()

	if Contains(txidHash) > SENDBOX {
		return nil, errors.New("Message not found!")
	}

	ret := new(objects.FullMessage)
	ret.Encrypted = new(encryption.EncryptedMessage)
	ret.Decrypted = new(objects.DecryptedMessage)

	s, err := LocalDB.Query("SELECT * FROM msg WHERE txid_hash=?", txidHash.GetBytes())
	if err == nil {
		recipient := make([]byte, 0, 0)
		sender := make([]byte, 0, 0)
		encrypted := make([]byte, 0, 0)
		decrypted := make([]byte, 0, 0)
		txidHash := make([]byte, 0, 0)
		var timestamp int64
		var purged bool
		var box int

		s.Scan(&txidHash, &recipient, &timestamp, &box, &encrypted, &decrypted, &purged, &sender)
		ret.MetaMessage.TxidHash.FromBytes(txidHash)
		ret.MetaMessage.Recipient = encryption.AddressToString(recipient)
		ret.MetaMessage.Sender = encryption.AddressToString(sender)
		ret.MetaMessage.Timestamp = time.Unix(timestamp, 0)
		ret.MetaMessage.Purged = purged
		ret.Encrypted.FromBytes(encrypted)
		if len(decrypted) > 0 {
			ret.Decrypted.FromBytes(decrypted)
		} else {
			ret.Decrypted = nil
		}
		return ret, nil
	}

	return nil, err

}
开发者ID:dcposch,项目名称:emp,代码行数:41,代码来源:dbAdmin.go


示例11: DeleteObject

func DeleteObject(obj objects.Hash) error {
	var err error
	switch Contains(obj) {
	case INBOX:
		fallthrough
	case SENDBOX:
		fallthrough
	case OUTBOX:
		err = LocalDB.Exec("DELETE FROM msg WHERE txid_hash=?", obj.GetBytes())
	case ADDRESS:
		err = LocalDB.Exec("DELETE FROM addressbook WHERE hash=?", obj.GetBytes())
	default:
		err = errors.New("Hash not found!")
	}

	if err == nil {
		Del(obj)
	}

	return err
}
开发者ID:dcposch,项目名称:emp,代码行数:21,代码来源:dbAdmin.go


示例12: GetPurge

// Get purge token from the database.
func GetPurge(log chan string, txidHash objects.Hash) *objects.Purge {
	mutex.Lock()
	defer mutex.Unlock()

	hash := txidHash.GetBytes()

	if hashList == nil || dbConn == nil {
		return nil
	}
	if hashList[string(hash)] != PURGE {
		return nil
	}

	for s, err := dbConn.Query("SELECT txid FROM purge WHERE hash=?", hash); err == nil; err = s.Next() {
		var txid []byte
		s.Scan(&txid) // Assigns 1st column to rowid, the rest to row
		p := new(objects.Purge)
		p.FromBytes(txid)
		return p
	}
	// Not Found
	return nil
}
开发者ID:dcposch,项目名称:emp,代码行数:24,代码来源:objects.go


示例13: DeleteMessage

func (service *EMPService) DeleteMessage(r *http.Request, args *[]byte, reply *NilParam) error {
	txidHash := new(objects.Hash)
	txidHash.FromBytes(*args)

	return localdb.DeleteMessage(txidHash)
}
开发者ID:dcposch,项目名称:emp,代码行数:6,代码来源:rpcmsg.go


示例14: Del

// Delete hash from Hash List
func Del(hashObj objects.Hash) {
	hash := string(hashObj.GetBytes())
	if hashList != nil {
		delete(hashList, hash)
	}
}
开发者ID:dcposch,项目名称:emp,代码行数:7,代码来源:localdb.go


示例15: Add

// Add to global Hash List.
func Add(hashObj objects.Hash, hashType int) {
	hash := string(hashObj.GetBytes())
	if hashList != nil {
		hashList[hash] = hashType
	}
}
开发者ID:dcposch,项目名称:emp,代码行数:7,代码来源:localdb.go


示例16: Start

// Starts a new TCP Server wth configuration specified in ApiConfig.
// Server will terminate cleanly only when data is sent to the Quit channel.
//
// See (struct ApiConfig) for details.
func Start(config *ApiConfig) {
	var err error
	var frame quibit.Frame

	defer quit(config)

	config.Log <- "Starting api..."

	// Start Database Services
	err = db.Initialize(config.Log, config.DbFile)
	defer db.Cleanup()
	if err != nil {
		config.Log <- fmt.Sprintf("Error initializing database: %s", err)
		config.Log <- "Quit"
		return
	}
	config.LocalVersion.Timestamp = time.Now().Round(time.Second)

	locVersion := objects.MakeFrame(objects.VERSION, objects.REQUEST, &config.LocalVersion)
	for str, _ := range config.NodeList.Nodes {
		locVersion.Peer = str
		config.SendQueue <- *locVersion
	}

	// Set Up Clocks
	second := time.Tick(2 * time.Second)
	minute := time.Tick(time.Minute)

	for {
		select {
		case frame = <-config.RecvQueue:
			config.Log <- fmt.Sprintf("Received %s frame...", CmdString(frame.Header.Command))
			switch frame.Header.Command {
			case objects.VERSION:
				version := new(objects.Version)
				err = version.FromBytes(frame.Payload)
				if err != nil {
					config.Log <- fmt.Sprintf("Error parsing version: %s", err)
				} else {
					fVERSION(config, frame, version)
				}
			case objects.PEER:
				nodeList := new(objects.NodeList)
				err = nodeList.FromBytes(frame.Payload)
				if err != nil {
					config.Log <- fmt.Sprintf("Error parsing peer list: %s", err)
				} else {
					fPEER(config, frame, nodeList)
				}
			case objects.OBJ:
				obj := new(objects.Obj)
				err = obj.FromBytes(frame.Payload)
				if err != nil {
					config.Log <- fmt.Sprintf("Error parsing obj list: %s", err)
				} else {
					fOBJ(config, frame, obj)
				}
			case objects.GETOBJ:
				getObj := new(objects.Hash)
				if len(frame.Payload) == 0 {
					break
				}
				err = getObj.FromBytes(frame.Payload)
				if err != nil {
					config.Log <- fmt.Sprintf("Error parsing getobj hash: %s", err)
				} else {
					fGETOBJ(config, frame, getObj)
				}
			case objects.PUBKEY_REQUEST:
				pubReq := new(objects.Hash)
				err = pubReq.FromBytes(frame.Payload)
				if err != nil {
					config.Log <- fmt.Sprintf("Error parsing pubkey request hash: %s", err)
				} else {
					fPUBKEY_REQUEST(config, frame, pubReq)
				}
			case objects.PUBKEY:
				pub := new(objects.EncryptedPubkey)
				err = pub.FromBytes(frame.Payload)
				if err != nil {
					config.Log <- fmt.Sprintf("Error parsing pubkey: %s", err)
				} else {
					fPUBKEY(config, frame, pub)
				}
			case objects.MSG:
				msg := new(objects.Message)
				err = msg.FromBytes(frame.Payload)
				if err != nil {
					config.Log <- fmt.Sprintf("Error parsing message: %s", err)
				} else {
					fMSG(config, frame, msg)
				}
			case objects.PUB:
				msg := new(objects.Message)
				err = msg.FromBytes(frame.Payload)
				if err != nil {
//.........这里部分代码省略.........
开发者ID:dcposch,项目名称:emp,代码行数:101,代码来源:api.go


示例17: OpenMessage

func (service *EMPService) OpenMessage(r *http.Request, args *[]byte, reply *objects.FullMessage) error {
	if !basicAuth(service.Config, r) {
		service.Config.Log <- fmt.Sprintf("Unauthorized RPC Request from: %s", r.RemoteAddr)
		return errors.New("Unauthorized")
	}

	var txidHash objects.Hash
	txidHash.FromBytes(*args)

	// Get Message from Database
	msg, err := localdb.GetMessageDetail(txidHash)
	if err != nil {
		return err
	}

	if msg.Encrypted == nil {
		*reply = *msg
		return nil
	}

	// If not decrypted, decrypt message and purge
	if msg.Decrypted == nil {
		recipient, err := localdb.GetAddressDetail(objects.MakeHash(encryption.StringToAddress(msg.MetaMessage.Recipient)))
		if err != nil {
			return err
		}

		if recipient.Privkey == nil {
			*reply = *msg
			return nil
		}

		// Decrypt Message
		decrypted := encryption.Decrypt(service.Config.Log, recipient.Privkey, msg.Encrypted)
		if len(decrypted) == 0 {
			*reply = *msg
			return nil
		}
		msg.Decrypted = new(objects.DecryptedMessage)
		msg.Decrypted.FromBytes(decrypted)

		// Update Sender

		x, y := encryption.UnmarshalPubkey(msg.Decrypted.Pubkey[:])
		address := encryption.GetAddress(service.Config.Log, x, y)
		addrStr := encryption.AddressToString(address)
		addrHash := objects.MakeHash(address)

		detail, _ := localdb.GetAddressDetail(addrHash)
		if detail == nil {
			detail = new(objects.AddressDetail)
		}
		detail.Address = address
		detail.String = addrStr
		detail.Pubkey = msg.Decrypted.Pubkey[:]

		localdb.AddUpdateAddress(detail)
		msg.MetaMessage.Sender = detail.String

		// Send Purge Request
		purge := new(objects.Purge)
		purge.Txid = msg.Decrypted.Txid

		service.Config.RecvQueue <- *objects.MakeFrame(objects.PURGE, objects.BROADCAST, purge)
		msg.MetaMessage.Purged = true

		localdb.AddUpdateMessage(msg, localdb.Contains(msg.MetaMessage.TxidHash))
	} else {
		if msg.MetaMessage.Purged == false && localdb.Contains(txidHash) == localdb.INBOX {
			msg.MetaMessage.Purged = true
			localdb.AddUpdateMessage(msg, localdb.Contains(msg.MetaMessage.TxidHash))
		}
	}

	*reply = *msg
	return nil
}
开发者ID:dcposch,项目名称:emp,代码行数:77,代码来源:rpcmsg.go


示例18: GetAddressDetail

func GetAddressDetail(addrHash objects.Hash) (*objects.AddressDetail, error) {
	localMutex.Lock()
	defer localMutex.Unlock()

	if Contains(addrHash) != ADDRESS {
		return nil, errors.New("Address not found!")
	}

	ret := new(objects.AddressDetail)

	s, err := LocalDB.Query("SELECT address, registered, pubkey, privkey, label, subscribed, encprivkey FROM addressbook WHERE hash=?", addrHash.GetBytes())
	if err == nil {
		s.Scan(&ret.Address, &ret.IsRegistered, &ret.Pubkey, &ret.Privkey, &ret.Label, &ret.IsSubscribed, &ret.EncPrivkey)
		ret.String = encryption.AddressToString(ret.Address)
		return ret, nil
	}

	return nil, err
}
开发者ID:dcposch,项目名称:emp,代码行数:19,代码来源:dbAdmin.go



注:本文中的emp/objects.Hash类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang encoding.BinaryMarshaler类代码示例发布时间:2022-05-24
下一篇:
Golang email.TriggerTrender函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap