Beispiel #1
0
func (rsp *flowAckResponse) WriteTo(w *xio.PacketWriter) error {
	if err := w.Write7BitValue64(rsp.fid); err != nil {
		return err
	}
	if err := w.Write7BitValue64(rsp.cnt); err != nil {
		return err
	}
	if err := storeFlowAck(rsp.ack, w); err != nil {
		return err
	}
	return nil
}
Beispiel #2
0
func (rsp *assignResponse) WriteTo(w *xio.PacketWriter) error {
	if err := w.Write32(rsp.xid); err != nil {
		return errors.New("assign.write xid")
	}
	if err := w.Write7BitValue64(uint64(len(rsp.responder))); err != nil {
		return errors.New("assign.write responder size")
	}
	if err := w.WriteBytes(rsp.responder); err != nil {
		return errors.New("assign.write responder")
	}
	if err := w.Write8(0x58); err != nil {
		return errors.New("assign.write mode")
	}
	return nil
}
Beispiel #3
0
func (rsp *helloResponse) WriteTo(w *xio.PacketWriter) error {
	if err := w.Write8(uint8(len(rsp.tag))); err != nil {
		return errors.New("hello.write tag.len")
	}
	if err := w.WriteBytes(rsp.tag); err != nil {
		return errors.New("hello.write tag")
	}
	if err := w.WriteString8(rsp.cookie); err != nil {
		return errors.New("hello.write value")
	}
	if err := w.WriteBytes(certificate); err != nil {
		return errors.New("hello.write certificate")
	}
	return nil
}
Beispiel #4
0
func (rsp *handshakeResponse) WriteTo(w *xio.PacketWriter) error {
	if err := w.Write8(uint8(len(rsp.tag))); err != nil {
		return errors.New("handshake.write tag.len")
	}
	if err := w.WriteBytes(rsp.tag); err != nil {
		return errors.New("handshake.write tag")
	}
	for i := 0; i < len(rsp.addrs); i++ {
		if err := w.WriteAddress(rsp.addrs[i], i == 0); err != nil {
			return errors.New("handshake.write addr")
		}
	}
	return nil
}
Beispiel #5
0
func storeFlowAck(ack *flowAck, w *xio.PacketWriter) error {
	if err := w.Write7BitValue64(ack.stage); err != nil {
		return err
	} else {
		stage := ack.stage
		for e := ack.conts.Front(); e != nil; e = e.Next() {
			r := e.Value.(*flowAckRange)
			if err := w.Write7BitValue64(r.beg - stage - 2); err != nil {
				return err
			}
			if err := w.Write7BitValue64(r.end - r.beg); err != nil {
				return err
			}
			stage = r.end
		}
		return nil
	}
}
Beispiel #6
0
func (rsp *handshakeResponse) WriteTo(w *xio.PacketWriter) error {
	if err := w.Write8(0x22); err != nil {
		return err
	}
	if err := w.Write8(0x21); err != nil {
		return err
	}
	if err := w.Write8(0x0f); err != nil {
		return err
	}
	if err := w.WriteBytes([]byte(rsp.pid)); err != nil {
		return err
	}
	if err := w.WriteAddress(rsp.addr, rsp.public); err != nil {
		return err
	}
	if err := w.WriteBytes(rsp.tag); err != nil {
		return err
	}
	return nil
}
Beispiel #7
0
func (rsp *flowResponse) WriteTo(w *xio.PacketWriter) error {
	flags := rsp.f.flags
	if rsp.header {
		flags |= flagsHeader
	}
	if err := w.Write8(flags); err != nil {
		return err
	}
	if rsp.header {
		if err := w.Write7BitValue64(rsp.fw.fid); err != nil {
			return err
		}
		if err := w.Write7BitValue64(rsp.f.stage); err != nil {
			return err
		}
		if err := w.Write7BitValue64(rsp.f.delta); err != nil {
			return err
		}
		if len(rsp.fw.signature) != 0 {
			if err := w.WriteString8(rsp.fw.signature); err != nil {
				return err
			}
			if rsp.fr.fid != 0 {
				more := 1
				if add, err := xio.SizeOf7BitValue64(rsp.fr.fid); err != nil {
					return err
				} else {
					more += add
				}
				if err := w.Write7BitValue64(uint64(more)); err != nil {
					return err
				}
				if err := w.Write8(0x0a); err != nil {
					return err
				}
				if err := w.Write7BitValue64(rsp.fr.fid); err != nil {
					return err
				}
			}
		}
		if err := w.Write8(0); err != nil {
			return err
		}
	}
	if err := w.WriteBytes(rsp.f.data); err != nil {
		return err
	}
	return nil
}