func (v *Assert) Uint16(value uint16) *Uint16Subject { return &Uint16Subject{ Subject: Subject{ a: v, disp: serial.Uint16ToString(value), }, value: value, } }
func (this *Listener) OnReceive(payload *alloc.Buffer, session *proxy.SessionInfo) { defer payload.Release() src := session.Source if valid := this.authenticator.Open(payload); !valid { log.Info("KCP|Listener: discarding invalid payload from ", src) return } if !this.running { return } this.Lock() defer this.Unlock() if !this.running { return } if payload.Len() < 4 { return } conv := serial.BytesToUint16(payload.Value) cmd := Command(payload.Value[2]) sourceId := src.NetAddr() + "|" + serial.Uint16ToString(conv) conn, found := this.sessions[sourceId] if !found { if cmd == CommandTerminate { return } log.Debug("KCP|Listener: Creating session with id(", sourceId, ") from ", src) writer := &Writer{ id: sourceId, hub: this.hub, dest: src, listener: this, } srcAddr := &net.UDPAddr{ IP: src.Address.IP(), Port: int(src.Port), } auth, err := this.config.GetAuthenticator() if err != nil { log.Error("KCP|Listener: Failed to create authenticator: ", err) } conn = NewConnection(conv, writer, this.Addr().(*net.UDPAddr), srcAddr, auth, this.config) select { case this.awaitingConns <- conn: case <-time.After(time.Second * 5): conn.Close() return } this.sessions[sourceId] = conn } conn.Input(payload.Value) }
// String returns the string presentation of this Port. func (this Port) String() string { return serial.Uint16ToString(this.Value()) }
func (subject *Uint16Subject) LessThan(expectation uint16) { if subject.value >= expectation { subject.Fail("is less than", serial.Uint16ToString(expectation)) } }
func (subject *Uint16Subject) GreaterThan(expectation uint16) { if subject.value <= expectation { subject.Fail("is greater than", serial.Uint16ToString(expectation)) } }
func (subject *Uint16Subject) Equals(expectation uint16) { if subject.value != expectation { subject.Fail("is equal to", serial.Uint16ToString(expectation)) } }
// String returns the string presentation of v Port. func (v Port) String() string { return serial.Uint16ToString(v.Value()) }