本文整理匯總了Golang中dbg.Printf函數的典型用法代碼示例。如果您正苦於以下問題:Golang Printf函數的具體用法?Golang Printf怎麽用?Golang Printf使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Printf函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: findMartiniContact
//given an ID, searches the local store, DHT, and if found unmarshals the bytes into a MartiniContact
func findMartiniContact(dm *DryMartini, hashedID kademlia.ID) (MartiniContact, bool) {
var mcBytes []byte
var mc MartiniContact
var err error
var success bool
mcBytes, success = dm.KademliaInst.ValueStore.Get(hashedID)
if !success {
success, _, mcBytes, err = kademlia.IterativeFind(dm.KademliaInst, hashedID, 2)
if err != nil {
dbg.Printf("findingMartiniContact failed. searching for key:%s. err:%s\n", ERRORS, hashedID.AsString(), err)
return mc, false
}
if success {
dbg.Printf("findMartiniContact: foundValue\n", Verbose)
} else {
dbg.Printf("IterativeFind failed to findvalue for key:%s\n", ERRORS, hashedID.AsString())
return mc, false
}
} else {
//dbg.Printf("found martiniContact locally. Key:%+v\n", hashedID)
}
err = json.Unmarshal(mcBytes, &mc)
dbg.Printf("findMartiniContact: 'foundContact.NodeIP:%s, Port:%d\n", Verbose, mc.NodeIP, mc.NodePort)
if err != nil {
dbg.Printf("Error unmarshaling found MartiniContact. %s\n", ERRORS, err)
panic(1)
}
return mc, true
}
示例2: UnwrapOlivesForPath
//decrypts encrypted data with pathKeys
//pathKeys are in order of closest Nodes key to furthest
func UnwrapOlivesForPath(dm *DryMartini, pathKeys []FlowIDSymmKeyPair, Data []byte) []byte {
var err error
var tempOlive Olive
var decData []byte
var theData []byte
pathLength := len(pathKeys)
theData = Data
for i := 0; i < pathLength; i++ {
//encrypt the Data (using furthest nodes key) and put it into tempOlive
dbg.Printf("UnwrapOlivesForPath; (len(pathkey)=%d) (len(theData)=%d) decrypting USING SYMMKEY and FLOWID: %+v\n", Verbose, len(pathKeys), len(theData), pathKeys[i])
decData = DecryptDataSymm(theData, pathKeys[i].SymmKey)
//marshal the temp Olive
err = json.Unmarshal(decData, &tempOlive)
if err != nil {
dbg.Printf("error marshalling Olive:%+v, err:%s\n", ERRORS, tempOlive, err)
panic(1)
}
theData = tempOlive.Data
}
return theData
}
示例3: StoreContactInfo
//stores dm's contactInfo in the DHT
func StoreContactInfo(dm *DryMartini) {
var err error
var mcBytes []byte
var key kademlia.ID = dm.KademliaInst.ContactInfo.NodeID.SHA1Hash()
mcBytes, err = json.Marshal(dm.myMartiniContact)
if err != nil {
dbg.Printf("error marshalling MartiniContact: %s\n", true, err)
}
var m MartiniContact
err = json.Unmarshal(mcBytes, &m)
if err != nil {
dbg.Printf("error: drymartini.PrintLocalData %s\n", (err != nil), err)
}
dbg.Printf("Print HashMap[%s]=%+v\n", Verbose, key.AsString(), m)
dbg.Printf("storing martiniContact:%+v %+v at ID: %x\n", Verbose, dm.myMartiniContact, mcBytes, key)
kademlia.MakeIterativeStore(dm.KademliaInst, key, mcBytes)
go func() {
//republish contact info ever 4 minutes. (expire time is hardcoded at 5minutes in kademlia.rpc)
for {
time.Sleep(time.Duration(4) * time.Minute)
kademlia.MakeIterativeStore(dm.KademliaInst, key, mcBytes)
}
}()
}
示例4: NewDryMartini
// Create a new DryMartini object with its own kademlia and RPC server
func NewDryMartini(listenStr string, keylen int) *DryMartini {
var err error
var s *rpc.Server
var dm *DryMartini
dm = new(DryMartini)
dm.EasyNewFlowIndex = 0
//Initialize key pair
dm.KeyPair, err = rsa.GenerateKey(rand.Reader, keylen)
if err != nil {
dbg.Printf("Failed to generate key! %s", true, err)
panic(1)
}
//Initialize flow struct
dm.Bartender = make(map[UUID]MartiniPick)
dm.Momento = make(map[UUID][]FlowIDSymmKeyPair)
dm.MapFlowIndexToFlowID = make(map[int]FlowInfo)
var host net.IP
var port uint16
host, port, err = kademlia.AddrStrToHostPort(listenStr)
//Initialize our Kademlia
//portStr := strconv.FormatUint(uint64(port), 10)
//var rpcPathStr string = kademlia.RpcPath+portStr
var rpcPathStr = "junk"
dbg.Printf("making new Kademlia with listenStr:%s, rpcPath\n", Verbose, listenStr, rpcPathStr)
dm.KademliaInst, s = kademlia.NewKademlia(listenStr, &rpcPathStr)
kademlia.BucketsAsArray(dm.KademliaInst)
//myMartiniContact <- ip, port, public key
dm.myMartiniContact.NodeIP = host.String()
dm.myMartiniContact.NodePort = port
dm.myMartiniContact.PubKey = dm.KeyPair.PublicKey.N.String()
dm.myMartiniContact.PubExp = dm.KeyPair.PublicKey.E
dbg.Printf("NewDryMartini: making new Kademlia with NodeIP: %s. NodePort:%d\n", Verbose, dm.myMartiniContact.NodeIP, dm.myMartiniContact.NodePort)
/*
if Verbose {
dbg.Printf("NodeIP: %s\n", dm.myMartiniContact.NodeIP)
dbg.Printf("NodePort: %d\n", dm.myMartiniContact.NodePort)
dbg.Printf("PubKey: %s\n", dm.myMartiniContact.PubKey)
dbg.Printf("PubExp: %d\n", dm.myMartiniContact.PubKey)
}*/
//register
err = s.Register(dm)
if err != nil {
dbg.Printf("Failed to register Drymartini! %s", true, err)
panic(1)
}
return dm
}
示例5: FindGoodPath
func FindGoodPath(dm *DryMartini) (bool, int) {
dbg.Printf("FindGoodPath: FlowIndexToFlowID map:%+v\n", Verbose, dm.MapFlowIndexToFlowID)
for index, flowInfo := range dm.MapFlowIndexToFlowID {
if time.Now().Before(flowInfo.expireAt) {
dbg.Printf("FindGoodPath: returning index:%d\n", Verbose, index)
return true, index
}
}
return false, -1
}
示例6: PrintArrayOfFoundNodes
func PrintArrayOfFoundNodes(array *[]FoundNode) {
dbg.Printf("Print Returned Found Nodes\n", Verbose)
if len(*array) == 0 {
return
}
for i, v := range *array {
dbg.Printf("[%d] --> %s %s %d\n", Verbose, i, v.NodeID.AsString(), v.IPAddr, v.Port)
}
return
}
示例7: Printf
func Printf(format string, k *Kademlia, doPrint bool, v ...interface{}) {
if RunningTests {
if v != nil {
(k.log).Printf(format, v...)
} else {
(k.log).Printf(format)
}
}
if v != nil {
dbg.Printf(format, doPrint, v...)
} else {
dbg.Printf(format, doPrint)
}
}
示例8: NewContact
func NewContact(AddrStr string) Contact {
var err error
var nodeID ID
var host net.IP
var port uint16
nodeID = NewRandomID()
host, port, err = AddrStrToHostPort(AddrStr)
if err != nil {
dbg.Printf("NewContact: error parsing Address STring to host/port:%s\n", true, err)
}
dbg.Printf("Creating new contact %s %s\n", Verbose, nodeID.AsString(), AddrStr)
return Contact{nodeID, host, port}
}
示例9: sendRPCsToFoundNodes
func sendRPCsToFoundNodes(k *Kademlia, findType int, localContact *Contact, searchID ID, slist *list.List, sentMap map[ID]bool, liveMap map[ID]bool) ([]FoundNode, []byte) {
//var value []byte
//log.Printf("sendRPCsToFoundNodes: Start\n")
dbg.Printf("sendRPCsToFoundNodes: shortlist:%+v\n", Verbose, *slist)
for e := slist.Front(); e != nil; e = e.Next() {
dbg.Printf("foundNode:%+v\n", Verbose, *(e.Value.(*FoundNode)))
}
resChan := make(chan *FindStarCallResponse, slist.Len())
var ret []FoundNode = make([]FoundNode, 0, slist.Len())
var rpcCount int = 0
var i int = 0
for e := slist.Front(); e != nil; e = e.Next() {
foundNode := e.Value.(*FoundNode)
remote := foundNode.FoundNodeToContact()
if sentMap[foundNode.NodeID] {
if liveMap[foundNode.NodeID] {
ret = append(ret, *foundNode)
}
i++
continue
}
rpcCount++
if findType == 1 { //FindNode
go MakeFindNodeCall(k, remote, searchID, resChan)
} else if findType == 2 { //FindValue
go MakeFindValueCall(k, remote, searchID, resChan)
}
}
//pull replies out of the channel
for ; rpcCount > 0; rpcCount-- {
findNodeResult := <-resChan
if findNodeResult.Responded {
k.UpdateChannel <- *findNodeResult.Responder.FoundNodeToContact()
if 2 == findType {
if findNodeResult.ReturnedFVRes.Value != nil {
var nArray []FoundNode = []FoundNode{*(findNodeResult.Responder)}
return nArray, findNodeResult.ReturnedFVRes.Value
}
}
dbg.Printf("adding 'live' responder to ret list:%+v\n", Verbose, *findNodeResult.Responder)
ret = append(ret, *findNodeResult.Responder)
i++
}
}
dbg.Printf("sendRPCsToFoundNodes returning:%+v\n", Verbose, ret)
return ret, nil
}
示例10: MakeMartiniPing
func MakeMartiniPing(dm *DryMartini, remoteHost net.IP, remotePort uint16) bool {
dbg.Printf("MakeMartiniPing %s %d\n", Verbose, remoteHost, remotePort)
//TODO: maybe should throw in a DoJoin(dm) here?
return kademlia.MakePingCall(dm.KademliaInst, remoteHost, remotePort)
}
示例11: FindValue
func (k *Kademlia) FindValue(req FindValueRequest, res *FindValueResult) error {
var err error
var found bool
//log.Printf("RPC:FindValue, from %s\n", req.Sender.NodeID.AsString())
// TODO: Implement.
//search for the value
//res.Value = data[req.Key]
//var found bool
//res.Value, found = k.HashMap[req.Key]
//Updated code for store handler --> seems too verbose
res.Value, found = k.ValueStore.Get(req.Key)
if found {
dbg.Printf("RPC:FindValue, found value [%s:%s]\n", Verbose, req.Key.AsString(), string(res.Value))
} else {
res.Nodes, err = FindKClosest(k, req.Key, req.Sender.NodeID)
}
res.MsgID = CopyID(req.MsgID)
//REVIEW: What kind of error can happen in this function?
return err
}
示例12: Update
//Call Update on Contact whenever you communicate successfully
func Update(k *Kademlia, triplet Contact) (success bool, err error) {
var dist int
var exists bool
var tripletP *list.Element
//find distance
dist = k.ContactInfo.NodeID.Distance(triplet.NodeID)
if -1 == dist {
dbg.Printf("Update dist == -1 return\n", Verbose)
return true, nil
}
//search kbucket and return pointer to the Triplet
exists, tripletP = k.Buckets[dist].Search(triplet.NodeID)
if exists {
//move to the tail
k.Buckets[dist].MoveToTail(tripletP)
success = true
} else {
if !k.Buckets[dist].IsFull() {
//just added to the tail
k.Buckets[dist].AddToTail(&triplet)
success = true
} else {
//log.Printf("A bucket is full! Checking...\n")
//ping the contant at the head
///get head
lFront := k.Buckets[dist].l.Front()
var remoteContact *Contact = lFront.Value.(*Contact)
///make ping
//log.Printf("Pinging the guy in the front of the list...\n")
succ := MakePingCall(k, remoteContact.Host, remoteContact.Port)
if !succ {
//log.Printf("He failed! Replacing\n")
//drop old
k.Buckets[dist].Drop(lFront)
//add new to tail
k.Buckets[dist].AddToTail(&triplet)
success = true
} else {
//log.Printf("He replied! Just ignore the new one\n")
//ignore new
//move the old one to the tail
k.Buckets[dist].MoveToTail(lFront)
success = true
}
}
}
if k.FirstKBucketStore && success {
k.DoJoinFlag = true
k.FirstKBucketStore = false
}
//REVIEW
//Should we return any error from this function?
return success, nil
}
示例13: DoJoin
//more arguments for a later time
//remoteAddr net.IP, remotePort uint16, doPing bool
func DoJoin(dm *DryMartini) bool {
var success bool
var secToWait time.Duration = 1
dbg.Printf("drymartini.DoJoin()\n", Verbose)
success = kademlia.DoJoin(dm.KademliaInst)
if !success {
return false
}
dm.DoJoinFlag = false
dbg.Printf("doJoin in %d sec\n", Verbose, secToWait)
time.Sleep(secToWait)
//Store our contact information
//TODO
StoreContactInfo(dm)
return true
}
示例14: StoreHandler
func StoreHandler(k *Kademlia) (chan *PutRequest, chan *GetRequest, chan ID) {
var puts chan *PutRequest
var gets chan *GetRequest
var deletes chan ID
puts = make(chan *PutRequest)
gets = make(chan *GetRequest)
deletes = make(chan ID)
go func() {
for {
var p *PutRequest
var g *GetRequest
var id ID
select {
case p = <-puts:
//put
if k.ValueStore.HashMap[p.key].expireTimer != nil {
k.ValueStore.HashMap[p.key].expireTimer.Stop()
}
dbg.Printf("In put handler for store. key->%s value->%s expires->%v\n", Verbose, p.key.AsString(), p.value, p.duration)
k.ValueStore.HashMap[p.key] = StoreItem{p.value, time.AfterFunc(p.duration, func() {
k.ValueStore.DeleteChannel <- p.key
}), time.Now()}
case g = <-gets:
//get
var si StoreItem
var found bool
dbg.Printf("In get handler for Store. key->%s", Verbose, g.key.AsString())
si, found = k.ValueStore.HashMap[g.key]
g.ReturnChan <- &GetResponse{si.Value, found}
case id = <-deletes:
delete(k.ValueStore.HashMap, id)
}
//log.Println("StoreHandler loop end\n")
}
}()
return puts, gets, deletes
}
示例15: FindOrGenPath
//check our list of existing paths, to see if there are any that haven't expired. Otherwise generate a new one
func FindOrGenPath(mDM *DryMartini, minLength int, maxLength int) (bool, int) {
var success bool
var flowIndex int
success, flowIndex = FindGoodPath(mDM)
if !success {
success, flowIndex = BarCrawl(mDM, "buildingCircuitForProxy", minLength, maxLength)
if !success {
dbg.Printf("there was an error building the circuit!\n", ERRORS)
}
}
return success, flowIndex
}