本文整理匯總了Golang中github.com/telehash/gogotelehash/e3x.Channel.RemoteHashname方法的典型用法代碼示例。如果您正苦於以下問題:Golang Channel.RemoteHashname方法的具體用法?Golang Channel.RemoteHashname怎麽用?Golang Channel.RemoteHashname使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/telehash/gogotelehash/e3x.Channel
的用法示例。
在下文中一共展示了Channel.RemoteHashname方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: serveTelehash
func (mod *module) serveTelehash(c *e3x.Channel) {
defer c.Close()
defer func() {
if err := recover(); err != nil {
const size = 64 << 10
buf := make([]byte, size)
buf = buf[:runtime.Stack(buf, false)]
mod.logf("thtp: panic serving %s: %v\n%s", c.RemoteHashname(), err, buf)
}
}()
req, err := mod.readRequest(c)
if err != nil {
return
}
rw := newResponseWriter(c)
defer rw.Flush()
mod.handler.ServeHTTP(rw, req)
}
示例2: handle_peer
func (mod *module) handle_peer(ch *e3x.Channel) {
defer ch.Kill()
log := mod.log.From(ch.RemoteHashname()).To(mod.e.LocalHashname())
// MUST allow router role
if mod.config.DisableRouter {
log.Println("drop: router disabled")
return
}
pkt, err := ch.ReadPacket()
if err != nil {
log.Printf("drop: failed to read packet: %s", err)
return
}
peerStr, ok := pkt.Header().GetString("peer")
if !ok {
log.Printf("drop: no peer in packet")
return
}
peer := hashname.H(peerStr)
// MUST have link to either endpoint
if mod.e.GetExchange(ch.RemoteHashname()) == nil && mod.e.GetExchange(peer) == nil {
log.Printf("drop: no link to either peer")
return
}
// MUST pass firewall
if mod.config.AllowPeer != nil && !mod.config.AllowPeer(ch.RemoteHashname(), peer) {
log.Printf("drop: blocked by firewall")
return
}
ex := mod.e.GetExchange(peer)
if ex == nil {
log.Printf("drop: no exchange to target")
// resolve?
return
}
token := cipherset.ExtractToken(pkt.Body(nil))
if token != cipherset.ZeroToken {
// add bridge back to requester
mod.RouteToken(token, ch.Exchange())
}
mod.connect(ex, bufpool.New().Set(pkt.Body(nil)))
}
示例3: handle_connect
//.........這裏部分代碼省略.........
} else {
// key packet
var parts = make(cipherset.Parts)
var csid uint8
for key, value := range inner.Header().Extra {
if len(key) != 2 {
continue
}
keyData, err := hex.DecodeString(key)
if err != nil {
continue
}
partCSID := keyData[0]
switch v := value.(type) {
case bool:
csid = partCSID
case string:
parts[partCSID] = v
}
}
hn, err := hashname.FromKeyAndIntermediates(csid, inner.Body(nil), parts)
if err != nil {
return
}
from = hn
pubKey, err := cipherset.DecodeKeyBytes(csid, inner.Body(nil), nil)
if err != nil {
return
}
remoteIdent, err = e3x.NewIdentity(cipherset.Keys{csid: pubKey}, parts, nil)
if err != nil {
return
}
}
if from == "" {
return
}
if mod.config.AllowConnect != nil && !mod.config.AllowConnect(from, ch.RemoteHashname()) {
return
}
x, err := mod.e.CreateExchange(remoteIdent)
if err != nil {
return
}
// when the BODY contains a handshake
if handshake != nil {
routerExchange := ch.Exchange()
routerAddr := &peerAddr{
router: routerExchange.RemoteHashname(),
}
conn := newConnection(x.RemoteHashname(), routerAddr, routerExchange, func() {
mod.unregisterConnection(routerExchange, x.LocalToken())
})
pipe, added := x.AddPipeConnection(conn, nil)
if added {
mod.registerConnection(routerExchange, x.LocalToken(), conn)
}
resp, ok := x.ApplyHandshake(handshake, pipe)
if !ok {
return
}
if resp != nil {
err = mod.peerVia(ch.Exchange(), from, resp)
if err != nil {
return
}
}
}
// when the BODY contains a key packet
if handshake == nil {
pkt, err := x.GenerateHandshake()
if err != nil {
return
}
err = mod.peerVia(ch.Exchange(), from, pkt)
if err != nil {
return
}
}
// Notify on-exchange callbacks
mod.getIntroduction(from).resolve(x, nil)
}