本文整理汇总了Golang中github.com/keybase/go-framed-msgpack-rpc.NewTransport函数的典型用法代码示例。如果您正苦于以下问题:Golang NewTransport函数的具体用法?Golang NewTransport怎么用?Golang NewTransport使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewTransport函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: pickFirstConnection
func (p *provisioner) pickFirstConnection() (err error) {
// This connection is auto-closed at the end of this function, so if
// you don't want it to close, then set it to nil. See the first
// case in the select below.
var conn net.Conn
var xp rpc.Transporter
defer func() {
if conn != nil {
conn.Close()
}
}()
// Only make a channel if we were provided a secret to start it with.
// If not, we'll just have to wait for a message on p.arg.SecretChannel
// and use the provisionee's channel.
if len(p.arg.Secret) != 0 {
if conn, err = NewConn(p.arg.Mr, p.arg.Secret, p.deviceID, p.arg.Timeout); err != nil {
return err
}
prot := keybase1.Kex2ProvisionerProtocol(p)
xp = rpc.NewTransport(conn, p.arg.Provisioner.GetLogFactory(), nil)
srv := rpc.NewServer(xp, nil)
if err = srv.Register(prot); err != nil {
return err
}
if err = srv.Run(true); err != nil {
return err
}
}
select {
case <-p.start:
p.conn = conn
conn = nil // so it's not closed in the defer()'ed close
p.xp = xp
case sec := <-p.arg.SecretChannel:
if len(sec) != SecretLen {
return ErrBadSecret
}
if p.conn, err = NewConn(p.arg.Mr, sec, p.deviceID, p.arg.Timeout); err != nil {
return err
}
p.xp = rpc.NewTransport(p.conn, p.arg.Provisioner.GetLogFactory(), nil)
case <-p.arg.Ctx.Done():
err = ErrCanceled
case <-time.After(p.arg.Timeout):
err = ErrTimedOut
}
return
}
开发者ID:polluks,项目名称:client,代码行数:52,代码来源:provisioner.go
示例2: Handle
func (d *Service) Handle(c net.Conn) {
xp := rpc.NewTransport(c, libkb.NewRPCLogFactory(), libkb.WrapError)
server := rpc.NewServer(xp, libkb.WrapError)
cl := make(chan error)
server.AddCloseListener(cl)
connID := d.G().NotifyRouter.AddConnection(xp, cl)
var logReg *logRegister
if d.isDaemon {
// Create a new log register object that the Log handler can use to
// register a logger. When this function finishes, the logger
// will be removed.
logReg = newLogRegister(d.logForwarder, d.G().Log)
defer logReg.UnregisterLogger()
}
if err := d.RegisterProtocols(server, xp, connID, logReg, d.G()); err != nil {
d.G().Log.Warning("RegisterProtocols error: %s", err)
return
}
if err := server.Run(false /* bg */); err != nil {
if err != io.EOF {
d.G().Log.Warning("Run error: %s", err)
}
}
d.G().Log.Debug("Handle() complete for connection %d", connID)
}
开发者ID:mattcurrycom,项目名称:client,代码行数:31,代码来源:main.go
示例3: Handle
func (d *Service) Handle(c net.Conn) {
xp := rpc.NewTransport(c, libkb.NewRPCLogFactory(), libkb.WrapError)
server := rpc.NewServer(xp, libkb.WrapError)
cl := make(chan error)
server.AddCloseListener(cl)
connID := d.G().NotifyRouter.AddConnection(xp, cl)
if err := d.RegisterProtocols(server, xp, connID, d.G()); err != nil {
d.G().Log.Warning("RegisterProtocols error: %s", err)
return
}
if d.isDaemon {
baseHandler := NewBaseHandler(xp)
logUI := LogUI{sessionID: 0, cli: baseHandler.getLogUICli()}
handle := d.G().Log.AddExternalLogger(&logUI)
defer d.G().Log.RemoveExternalLogger(handle)
}
if err := server.Run(false /* bg */); err != nil {
if err != io.EOF {
d.G().Log.Warning("Run error: %s", err)
}
}
}
开发者ID:stevefox,项目名称:client,代码行数:27,代码来源:main.go
示例4: Dial
// Dial is an implementation of the ConnectionTransport interface.
func (ct *ConnectionTransportTLS) Dial(ctx context.Context) (
rpc.Transporter, error) {
var conn net.Conn
err := runUnlessCanceled(ctx, func() error {
// load CA certificate
certs := x509.NewCertPool()
if !certs.AppendCertsFromPEM(ct.rootCerts) {
return errors.New("Unable to load root certificates")
}
// connect
config := tls.Config{RootCAs: certs}
var err error
conn, err = tls.Dial("tcp", ct.srvAddr, &config)
return err
})
if err != nil {
return nil, err
}
transport := rpc.NewTransport(conn, libkb.NewRPCLogFactory(), libkb.WrapError)
ct.mutex.Lock()
defer ct.mutex.Unlock()
ct.conn = conn
ct.stagedTransport = transport
return transport, nil
}
开发者ID:gozes,项目名称:kbfs-beta,代码行数:27,代码来源:connection.go
示例5: Dial
func (t *connTransport) Dial(context.Context) (rpc.Transporter, error) {
var err error
t.conn, err = net.Dial("tcp", t.host)
if err != nil {
return nil, err
}
t.stagedTransport = rpc.NewTransport(t.conn, libkb.NewRPCLogFactory(t.G()), libkb.WrapError)
return t.stagedTransport, nil
}
开发者ID:qbit,项目名称:client,代码行数:9,代码来源:rpc.go
示例6: Dial
func (t *pingGregorTransport) Dial(context.Context) (rpc.Transporter, error) {
t.G().Log.Debug("pingGregorTransport Dial", t.host)
var err error
t.conn, err = net.Dial("tcp", t.host)
if err != nil {
return nil, err
}
t.stagedTransport = rpc.NewTransport(t.conn, nil, nil)
return t.stagedTransport, nil
}
开发者ID:qbit,项目名称:client,代码行数:10,代码来源:cmd_ping.go
示例7: Handle
func (d *Service) Handle(c net.Conn) {
xp := rpc.NewTransport(c, libkb.NewRPCLogFactory(d.G()), libkb.WrapError)
server := rpc.NewServer(xp, libkb.WrapError)
cl := make(chan error, 1)
connID := d.G().NotifyRouter.AddConnection(xp, cl)
var logReg *logRegister
if d.isDaemon {
// Create a new log register object that the Log handler can use to
// register a logger. When this function finishes, the logger
// will be removed.
logReg = newLogRegister(d.logForwarder, d.G().Log)
defer logReg.UnregisterLogger()
}
shutdowners, err := d.RegisterProtocols(server, xp, connID, logReg, d.G())
var shutdownOnce sync.Once
shutdown := func() error {
shutdownOnce.Do(func() {
for _, shutdowner := range shutdowners {
shutdowner.Shutdown()
}
})
return nil
}
// Clean up handlers when the connection closes.
defer shutdown()
// Make sure shutdown is called when service shuts down but the connection
// isn't closed yet.
d.G().PushShutdownHook(shutdown)
if err != nil {
d.G().Log.Warning("RegisterProtocols error: %s", err)
return
}
// Run the server and wait for it to finish.
<-server.Run()
// err is always non-nil.
err = server.Err()
cl <- err
if err != io.EOF {
d.G().Log.Warning("Run error: %s", err)
}
d.G().Log.Debug("Handle() complete for connection %d", connID)
}
开发者ID:qbit,项目名称:client,代码行数:51,代码来源:main.go
示例8: startServer
func (p *provisionee) startServer(s Secret) (err error) {
if p.conn, err = NewConn(p.arg.Ctx, p.arg.Mr, s, p.deviceID, p.arg.Timeout); err != nil {
return err
}
prot := keybase1.Kex2ProvisioneeProtocol(p)
p.xp = rpc.NewTransport(p.conn, p.arg.Provisionee.GetLogFactory(), nil)
srv := rpc.NewServer(p.xp, nil)
if err = srv.Register(prot); err != nil {
return err
}
p.server = srv
p.serverDoneCh = srv.Run()
return nil
}
开发者ID:qbit,项目名称:client,代码行数:15,代码来源:provisionee.go
示例9: GetSocket
func (g *GlobalContext) GetSocket(clearError bool) (net.Conn, rpc.Transporter, bool, error) {
// Protect all global socket wrapper manipulation with a
// lock to prevent race conditions.
g.socketWrapperMu.Lock()
defer g.socketWrapperMu.Unlock()
isNew := false
needWrapper := false
if g.SocketWrapper == nil {
needWrapper = true
} else if g.SocketWrapper.xp != nil && !g.SocketWrapper.xp.IsConnected() {
// need reconnect
G.Log.Debug("rpc transport disconnected, reconnecting...")
needWrapper = true
}
if needWrapper {
sw := SocketWrapper{}
if g.LoopbackListener != nil {
sw.conn, sw.err = g.LoopbackListener.Dial()
} else if g.SocketInfo == nil {
sw.err = fmt.Errorf("Cannot get socket in standalone mode")
} else {
sw.conn, sw.err = g.SocketInfo.DialSocket()
isNew = true
}
if sw.err == nil {
sw.xp = rpc.NewTransport(sw.conn, NewRPCLogFactory(), WrapError)
}
g.SocketWrapper = &sw
}
sw := g.SocketWrapper
if sw.err != nil && clearError {
g.SocketWrapper = nil
}
return sw.conn, sw.xp, isNew, sw.err
}
开发者ID:Varjelus,项目名称:keybase-client,代码行数:41,代码来源:socket.go
示例10: NewTransportFromSocket
func NewTransportFromSocket(g *GlobalContext, s net.Conn) rpc.Transporter {
return rpc.NewTransport(s, NewRPCLogFactory(g), WrapError)
}
开发者ID:keybase,项目名称:kbfs-beta,代码行数:3,代码来源:socket.go
注:本文中的github.com/keybase/go-framed-msgpack-rpc.NewTransport函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论