当前位置: 首页>>代码示例>>Golang>>正文


Golang counts.Count函数代码示例

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


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

示例1: handleAssign

func (h *Handshake) handleAssign(r *xio.PacketReader) (rtmfp.ResponseMessage, uint32, error) {
	if req, err := parseAssignRequest(r); err != nil {
		return nil, 0, err
	} else {
		cookie := cookies.Find(string(req.cookie))
		if cookie == nil {
			return nil, 0, errors.New("assign.cookie not found")
		}
		cookie.Lock()
		defer cookie.Unlock()
		if cookie.Xid == 0 {
			responder, encrypt, decrypt := rtmfp.ComputeSharedKeys(h, req.pubkey, req.initiator)
			cookie.Pid = req.pid
			cookie.Responder = responder
			if xid, err := session.Create(req.yid, cookie.Pid, cookie.Value(), encrypt, decrypt, h.lport, h.raddr); err != nil {
				counts.Count("handshake.session.error", 1)
				return nil, 0, errors.New(fmt.Sprintf("assign.create session = %v", err))
			} else {
				cookie.Xid = xid
				counts.Count("handshake.assign", 1)
				xlog.SssLog.Printf("[join] %s [%s] xid = %d\n", xlog.StringToHex(cookie.Pid), h.raddr, xid)
			}
			xlog.OutLog.Printf("[handshake]: new session xid = %d from [%s]\n", cookie.Xid, h.raddr)
		}
		return &assignResponse{cookie.Xid, cookie.Responder}, req.yid, nil
	}
}
开发者ID:edgarcai,项目名称:xserver,代码行数:27,代码来源:handshake.go

示例2: New

func New() *Cookie {
	cookies.Lock()
	defer cookies.Unlock()
	now := time.Now().UnixNano()
	buf := make([]byte, CookieSize)
	for i, v := 0, now; i < 8; i, v = i+1, v>>8 {
		buf[i] = uint8(v)
	}
	rnd := xio.NewRandomReader(now)
	for i := 0; i < 4; i++ {
		rnd.ReadBytes(buf[8:])
		value := string(buf)
		if c := cookies.values[value]; c != nil {
			continue
		}
		c := &Cookie{}
		c.value = value
		c.alloctime = now
		cookies.values[value] = c
		counts.Count("cookie.new", 1)
		return c
	}
	counts.Count("cookie.null", 1)
	return nil
}
开发者ID:edgarcai,项目名称:xserver,代码行数:25,代码来源:cookies.go

示例3: Send

func Send(lport uint16, raddr *net.UDPAddr, data []byte) {
	if len(data) > 1400 {
		counts.Count("udp.toobig", 1)
		xlog.ErrLog.Printf("[udp]: udp-%d packet is too big, size = %d\n", lport, len(data))
	} else if srv := servers[lport]; srv == nil {
		counts.Count("udp.notfound", 1)
		xlog.ErrLog.Printf("[udp]: udp-%d not found\n", lport)
	} else {
		srv.Send(raddr, data)
	}
}
开发者ID:edgarcai,项目名称:xserver,代码行数:11,代码来源:servers.go

示例4: Exit

func Exit(xid uint32, raddr *net.UDPAddr) {
	if clt := tcp.GetClient(); clt == nil {
		return
	} else if bs, err := newXRequest(xid, raddr, "exit", 0, nil, true); err != nil {
		counts.Count("rpc.exit.error", 1)
		xlog.ErrLog.Printf("[rpc]: rpc exit error = '%v'\n", err)
	} else {
		counts.Count("rpc.exit", 1)
		async.Call(uint64(xid), func() {
			clt.Send(bs)
		})
	}
}
开发者ID:edgarcai,项目名称:xserver,代码行数:13,代码来源:rpc.go

示例5: handleHello

func (h *Handshake) handleHello(r *xio.PacketReader) (rtmfp.ResponseMessage, error) {
	if req, err := parseHelloRequest(r); err != nil {
		return nil, err
	} else {
		switch req.mode {
		default:
			return nil, errors.New(fmt.Sprintf("hello.unknown mode = 0x%02x", req.mode))
		case 0x0f:
			if s := session.FindByPid(string(req.epd)); s == nil {
				counts.Count("p2p.session.notfound", 1)
				return nil, &handshakeError{"hello.handshake.session not found", req.epd, h.raddr}
			} else if addrs, ok := s.Handshake(req.tag, h.raddr); !ok {
				counts.Count("p2p.session.hasclosed", 1)
				return nil, &handshakeError{"hello.handshake.session has been closed", req.epd, h.raddr}
			} else {
				counts.Count("p2p.handshake", 1)
				return &handshakeResponse{req.tag, addrs}, nil
			}
		case 0x0a:
			if uri, err := url.ParseRequestURI(string(req.epd)); err != nil {
				return nil, errors.New("hello.parse uri")
			} else if app := uri.Path; len(app) == 0 {
				return nil, errors.New("hello.parse app")
			} else {
				if ss := strings.Split(app, "/"); len(ss) != 1 {
					app = ""
					for _, s := range ss {
						if len(s) != 0 {
							app = s
							break
						}
					}
				}
				if len(app) == 0 || !args.IsAuthorizedApp(app) {
					counts.Count("handshake.app.unauthorized", 1)
					return nil, errors.New(fmt.Sprintf("hello.unauthorized app = %s", app))
				}
			}
			cookie := cookies.New()
			if cookie == nil {
				return nil, errors.New("hello.null cookie")
			}
			cookie.Lock()
			defer cookie.Unlock()
			counts.Count("handshake.hello", 1)
			xlog.OutLog.Printf("[handshake]: new cookie from [%s]\n", h.raddr)
			return &helloResponse{req.tag, cookie.Value()}, nil
		}
	}
}
开发者ID:edgarcai,项目名称:xserver,代码行数:50,代码来源:handshake.go

示例6: Call

func Call(xid uint32, raddr *net.UDPAddr, callback float64, data []byte, reliable bool) {
	if clt := tcp.GetClient(); clt == nil {
		counts.Count("rpc.call.noclient", 1)
		xlog.ErrLog.Printf("[rpc]: rpc is disabled\n")
	} else if bs, err := newXRequest(xid, raddr, "call", callback, data, reliable); err != nil {
		counts.Count("rpc.call.error", 1)
		xlog.ErrLog.Printf("[rpc]: rpc call error = '%v'\n", err)
	} else {
		counts.Count("rpc.call", 1)
		async.Call(uint64(xid), func() {
			clt.Send(bs)
		})
	}
}
开发者ID:edgarcai,项目名称:xserver,代码行数:14,代码来源:rpc.go

示例7: flush

func flush(s *Session, msgs []rtmfp.ResponseMessage) {
	lport, raddr := s.lport, s.raddr
	if data, err := rtmfp.PacketToBytes(&packet{s.yid, s.manage.lasttime, s.stmptime, msgs}); err != nil {
		counts.Count("session.tobytes.error", 1)
		xlog.ErrLog.Printf("[session]: packet to bytes error = '%v'\n", err)
		return
	} else {
		xlog.OutLog.Printf("[session]: send addr = [%s], data.len = %d\n%s\n", raddr, len(data), utils.Formatted(data))
		if data, err = rtmfp.EncodePacket(s, s.yid, data); err != nil {
			counts.Count("session.encode.error", 1)
			xlog.ErrLog.Printf("[session]: encode packet error = '%v'\n", err)
			return
		}
		udp.Send(lport, raddr, data)
	}
}
开发者ID:edgarcai,项目名称:xserver,代码行数:16,代码来源:session.go

示例8: init

func init() {
	for i := 0; i < len(groups); i++ {
		g := &groups[i]
		g.cond = sync.NewCond(&g.lock)
		g.list = list.New()
		main := func() {
			defer func() {
				if x := recover(); x != nil {
					counts.Count("async.panic", 1)
					xlog.ErrLog.Printf("[async]: panic = %v\n%s\n", x, utils.Trace())
				}
			}()
			for {
				var f func()
				g.lock.Lock()
				if e := g.list.Front(); e != nil {
					f = g.list.Remove(e).(func())
				} else {
					g.cond.Wait()
				}
				g.lock.Unlock()
				if f != nil {
					f()
				}
			}
		}
		go func() {
			for {
				main()
			}
		}()
	}
}
开发者ID:edgarcai,项目名称:xserver,代码行数:33,代码来源:async.go

示例9: Find

func Find(value string) *Cookie {
	cookies.Lock()
	c := cookies.values[value]
	cookies.Unlock()
	if c == nil {
		counts.Count("cookie.notfound", 1)
	}
	return c
}
开发者ID:edgarcai,项目名称:xserver,代码行数:9,代码来源:cookies.go

示例10: DecodeXMessage

func DecodeXMessage(bs []byte) *XMessage {
	x := &XMessage{}
	if err := proto.Unmarshal(bs, x); err != nil {
		counts.Count("rpc.xmessage.error", 1)
		xlog.ErrLog.Printf("[rpc]: rpc decode.xmessage error = '%v'\n", err)
		return nil
	}
	return x
}
开发者ID:edgarcai,项目名称:xserver,代码行数:9,代码来源:rpc.go

示例11: newHandshake

func newHandshake() *Handshake {
	h := &Handshake{}
	h.AESEngine = rtmfp.NewAESEngine()
	if err := h.SetKey(cryptkey, cryptkey); err != nil {
		utils.Panic(fmt.Sprintf("handshake init error = '%v'", err))
	}
	h.DHEngine = rtmfp.NewDHEngine()
	counts.Count("handshake.new", 1)
	return h
}
开发者ID:edgarcai,项目名称:xserver,代码行数:10,代码来源:handshake.go

示例12: HandlePacket

func HandlePacket(lport uint16, raddr *net.UDPAddr, data []byte) {
	h := getHandshake()
	if h == nil {
		return
	}
	defer putHandshake(h)

	var err error
	if data, err = rtmfp.DecodePacket(h, data); err != nil {
		counts.Count("handshake.decode.error", 1)
		xlog.ErrLog.Printf("[handshake]: decode error = '%v'\n", err)
		return
	}
	xlog.OutLog.Printf("[handshake]: recv addr = [%s], data.len = %d\n%s\n", raddr, len(data), utils.Formatted(data))

	h.lport, h.raddr = lport, raddr

	var pkt *packet
	if pkt, err = h.handle(xio.NewPacketReader(data[6:])); err != nil {
		counts.Count("handshake.handle.error", 1)
		xlog.ErrLog.Printf("[handshake]: handle error = '%v'\n", err)
		return
	} else if pkt == nil {
		xlog.OutLog.Printf("[handshake]: response packet is empty\n")
		return
	}

	if data, err = rtmfp.PacketToBytes(pkt); err != nil {
		counts.Count("handshake.tobytes.error", 1)
		xlog.ErrLog.Printf("[handshake]: packet to bytes error = '%v'\n", err)
		return
	}
	xlog.OutLog.Printf("[handshake]: send addr = [%s], data.len = %d\n%s\n", raddr, len(data), utils.Formatted(data))

	if data, err = rtmfp.EncodePacket(h, pkt.yid, data); err != nil {
		counts.Count("handshake.encode.error", 1)
		xlog.ErrLog.Printf("[handshake]: encode packet error = '%v'\n", err)
		return
	}
	udp.Send(lport, raddr, data)
}
开发者ID:edgarcai,项目名称:xserver,代码行数:41,代码来源:handshake.go

示例13: handleFlowRequest

func (s *Session) handleFlowRequest(req *flowRequest) error {
	if fr, err := s.getFlowReader(req.fid, req.signature); err != nil {
		counts.Count("session.flow.error", 1)
		return errors.New("flow.create flow reader")
	} else if fr != nil {
		fr.AddFragments(req.stageack, req.Fragments()...)
		fr.CommitAck()
		return nil
	} else {
		xlog.OutLog.Printf("[session]: xid = %d, reader.fid = %d, flow not found\n", s.xid, req.fid)
		return nil
	}
}
开发者ID:edgarcai,项目名称:xserver,代码行数:13,代码来源:session.go

示例14: Close

func (s *Session) Close() {
	if s.closed {
		return
	}
	s.closed = true
	for _, fw := range s.writers {
		fw.reader.handler.OnClose()
	}
	s.send(newErrorResponse())
	counts.Count("session.close", 1)
	xlog.OutLog.Printf("[session]: xid = %d, session closed\n", s.xid)
	rpc.Exit(s.xid, s.raddr)
}
开发者ID:edgarcai,项目名称:xserver,代码行数:13,代码来源:session.go

示例15: Create

func Create(yid uint32, pid string, cookie string, encrypt, decrypt []byte, lport uint16, raddr *net.UDPAddr) (uint32, error) {
	s := &Session{}
	s.xid = 0
	s.yid = yid
	s.pid = pid
	s.lport, s.raddr = lport, raddr
	s.addrs = nil
	s.cookie = cookie
	s.closed = false
	s.manage.cnt, s.manage.lasttime = 0, time.Now().UnixNano()
	s.stmptime = 0
	s.AESEngine = rtmfp.NewAESEngine()
	if err := s.SetKey(encrypt, decrypt); err != nil {
		return 0, err
	}
	s.lastfid = 0
	s.lastsid = 0
	s.mainfw = nil
	s.readers = make(map[uint64]*flowReader)
	s.writers = make(map[uint64]*flowWriter)
	s.rsplist.Init()

	sessions.Lock()
	defer sessions.Unlock()

	xid := sessions.lastxid
	for {
		xid++
		if xid == 0 {
			continue
		}
		if xid == sessions.lastxid {
			return 0, errors.New("too many sessions")
		}
		if getSessionByXid(xid) == nil {
			break
		}
	}
	s.xid = xid
	sessions.lastxid = xid
	addSessionByXid(xid, s)
	addSessionByPid(pid, s)

	m := &sessions.manages[int(xid%uint32(len(sessions.manages)))]
	m.Lock()
	m.freshlist.PushBack(s)
	m.Unlock()

	counts.Count("session.new", 1)
	return xid, nil
}
开发者ID:edgarcai,项目名称:xserver,代码行数:51,代码来源:sessions.go


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