本文整理汇总了Golang中dbg.Printf函数的典型用法代码示例。如果您正苦于以下问题:Golang Printf函数的具体用法?Golang Printf怎么用?Golang Printf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Printf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:johhud1,项目名称:KademliaMixNetwork,代码行数:31,代码来源:drymartini.go
示例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
}
开发者ID:johhud1,项目名称:KademliaMixNetwork,代码行数:27,代码来源:drymartini.go
示例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)
}
}()
}
开发者ID:johhud1,项目名称:KademliaMixNetwork,代码行数:27,代码来源:drymartini.go
示例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
}
开发者ID:johhud1,项目名称:KademliaMixNetwork,代码行数:59,代码来源:drymartini.go
示例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
}
开发者ID:johhud1,项目名称:KademliaMixNetwork,代码行数:10,代码来源:drymartini.go
示例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
}
开发者ID:johhud1,项目名称:KademliaMixNetwork,代码行数:10,代码来源:rpc.go
示例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)
}
}
开发者ID:johhud1,项目名称:KademliaMixNetwork,代码行数:14,代码来源:dbg.go
示例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}
}
开发者ID:johhud1,项目名称:KademliaMixNetwork,代码行数:15,代码来源:rpc.go
示例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
}
开发者ID:johhud1,项目名称:KademliaMixNetwork,代码行数:48,代码来源:kademlia.go
示例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)
}
开发者ID:johhud1,项目名称:KademliaMixNetwork,代码行数:7,代码来源:rpc.go
示例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
}
开发者ID:johhud1,项目名称:KademliaMixNetwork,代码行数:26,代码来源:rpc.go
示例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
}
开发者ID:johhud1,项目名称:KademliaMixNetwork,代码行数:60,代码来源:kademlia.go
示例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
}
开发者ID:johhud1,项目名称:KademliaMixNetwork,代码行数:22,代码来源:drymartini.go
示例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
}
开发者ID:johhud1,项目名称:KademliaMixNetwork,代码行数:41,代码来源:kademlia.go
示例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
}
开发者ID:johhud1,项目名称:KademliaMixNetwork,代码行数:13,代码来源:drymartini.go
示例16: WrapOlivesForPath
//encrypts data with pathKeys
//pathKeys are in order of closest Nodes key to furthest
func WrapOlivesForPath(dm *DryMartini, flowID UUID, pathKeyFlows []FlowIDSymmKeyPair, Data []byte) []byte {
var err error
pathLength := len(pathKeyFlows)
//if only 1 MartiniContact exists in path, then we only construct 1 Olive..
//but that should probably never happen, (assuming always more than 1 hop atm)
var innerOlive Olive
//might wanna delete this at some point, should be unneccessary. inner olive doesn't need flow id
innerOlive.FlowID = flowID
innerOlive.Data = Data
//dbg.Printf("We are packaging data: %s", string(Data))
var theData []byte
theData, err = json.Marshal(innerOlive)
if err != nil {
dbg.Printf("error marshalling inner Olive:%+v\n", ERRORS, innerOlive)
panic(1)
}
var tempOlive Olive
for i := pathLength - 1; i > 0; i-- {
//important that flowID is shifted by 1
tempOlive.FlowID = pathKeyFlows[i].FlowID
//encrypt the Data (using furthest nodes key) and put it into tempOlive
tempOlive.Data = EncryptDataSymm(theData, pathKeyFlows[i].SymmKey)
dbg.Printf("USING SYMMKEY and FLOWID: %+v\n", Verbose, pathKeyFlows[i])
//marshal the temp Olive
theData, err = json.Marshal(tempOlive)
if err != nil {
dbg.Printf("error marshalling Olive:%+v, err:%s\n", ERRORS, tempOlive, err)
panic(1)
}
}
//dbg.Printf("USING SymmKEY and FlowID: %v\n", pathKeyFlows[0])
theData = EncryptDataSymm(theData, pathKeyFlows[0].SymmKey)
return theData
}
开发者ID:johhud1,项目名称:KademliaMixNetwork,代码行数:42,代码来源:drymartini.go
示例17: MakeSendCall
//makes a DryMartini.ServeDrink call on address with the Olive data, returning success and returned data if any
func MakeSendCall(dataLump Olive, nextNodeAddrStr string) (bool, []byte) {
var client *rpc.Client
var err error
dbg.Printf("MakeSendCall:: next: %s!", Verbose, nextNodeAddrStr)
if kademlia.RunningTests == true {
//log.Printf("Unimplemented\n")
//panic(1)
var nextNodePort string = strings.Split(nextNodeAddrStr, ":")[1]
if nextNodePort == "" {
log.Printf("error getting next port: MakeSendCall\n")
panic(1)
}
var portstr string = kademlia.RpcPath + nextNodePort
log.Printf("test MakeSendCall to rpcPath:%s\n", portstr)
client, err = rpc.DialHTTPPath("tcp", nextNodeAddrStr, portstr)
} else {
client, err = rpc.DialHTTP("tcp", nextNodeAddrStr)
}
if err != nil {
log.Printf("Error: MakeSendCall, DialHTTP, %s\n", err)
return false, nil
}
//make rpc
var res *ServerResp = new(ServerResp)
var req *ServerData = new(ServerData)
req.Sent = dataLump
err = client.Call("DryMartini.ServeDrink", req, res)
if err != nil {
log.Printf("Error: SendCall, Call, %s\n", err)
return false, nil
}
dbg.Printf("got SendCall response: %s:%v\n", Verbose, nextNodeAddrStr, res.Success)
client.Close()
return res.Success, res.Data
}
开发者ID:johhud1,项目名称:KademliaMixNetwork,代码行数:41,代码来源:rpc.go
示例18: FindNode
func (k *Kademlia) FindNode(req FindNodeRequest, res *FindNodeResult) error {
var err error
//Update(k, req.Sender)
k.UpdateChannel <- req.Sender
dbg.Printf("RPC: FindNode from %s ---> %s\n", Verbose, req.Sender.NodeID.AsString(), k.ContactInfo.AsString())
res.Nodes, err = FindKClosest(k, req.NodeID, req.Sender.NodeID)
res.MsgID = CopyID(req.NodeID)
///REVIEW: What kind of error can happen in this function?
return err
}
开发者ID:johhud1,项目名称:KademliaMixNetwork,代码行数:14,代码来源:rpc.go
示例19: SendData
//send Data using the path info stored at FlowIndex
func SendData(dm *DryMartini, flowIndex int, data string) (response string, success bool) {
var flowInfo FlowInfo
var flowID UUID
var found bool
//map index to flowID
flowInfo, found = dm.MapFlowIndexToFlowID[flowIndex]
if !found {
dbg.Printf("No map from flowIndex to flowID\n", ERRORS)
return "", false
} else {
flowID = flowInfo.FlowID
dbg.Printf("Found map from flowIndex to flowID\n", Verbose)
}
//wrap data
var sendingOlive Olive
sendingOlive.Data = WrapOlivesForPath(dm, flowID, dm.Momento[flowID], []byte(data))
//first olive gets flowID for first node in path
sendingOlive.FlowID = dm.Momento[flowID][0].FlowID
var nextNodeAddrStr string = dm.Bartender[flowID].NextNodeIP + ":" + strconv.FormatUint(uint64(dm.Bartender[flowID].NextNodePort), 10)
//make send rpc
var encResponseData []byte
var responseData []byte
success, encResponseData = MakeSendCall(sendingOlive, nextNodeAddrStr)
if !success {
dbg.Printf("Some terrible error happened while sending\n", ERRORS)
return "", false
}
//unwrap data
responseData = UnwrapOlivesForPath(dm, dm.Momento[flowID], encResponseData)
log.Printf("SEND REPLY: %s\n", string(responseData))
return string(responseData), true
}
开发者ID:johhud1,项目名称:KademliaMixNetwork,代码行数:37,代码来源:drymartini.go
示例20: DoHTTPRequest
func DoHTTPRequest(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
var success bool
var flowIndex int
var response string
success, flowIndex = drymartini.FindOrGenPath(myDryMartini, DefaultCircLength, DefaultCircLength)
if !success {
return r, goproxy.NewResponse(r, goproxy.ContentTypeText, http.StatusInternalServerError, "error building circuit")
}
response, success = drymartini.SendData(myDryMartini, flowIndex, r.URL.String())
if !success {
log.Printf("there was an error sending the request:%s\n", r.URL.String())
return r, goproxy.NewResponse(r, goproxy.ContentTypeText, http.StatusInternalServerError, "error sending request")
}
var contentType string = http.DetectContentType([]byte(response))
dbg.Printf("detected response as having content-type:%s\n", pVerb, contentType)
dbg.Printf("request url was:%s\n", pVerb, r.URL.String())
//gotta set the content-type manually, detectContentType doesn't seem to work for .css
//kept setting it as "text/plain". there's probably a much nice way than this, whatevs. fake it til you make it
if strings.Contains(r.URL.String(), ".css") {
contentType = "text/css"
}
return r, goproxy.NewResponse(r, contentType, http.StatusOK, response)
}
开发者ID:johhud1,项目名称:KademliaMixNetwork,代码行数:24,代码来源:proxy.main.go
注:本文中的dbg.Printf函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论