示例#1
0
文件: sbtcp.go 项目: ikravets/ev
func WriteMessage(w io.Writer, m Message) (err error) {
	defer errs.PassE(&err)
	errs.CheckE(m.encodePayload())
	var mt MessageType
	switch m.(type) {
	case *MessageDebug:
		mt = TypeDebug
	case *MessageLoginAccepted:
		mt = TypeLoginAccepted
	case *MessageLoginRejected:
		mt = TypeLoginRejected
	case *MessageSequencedData:
		mt = TypeSequencedData
	case *MessageHeartbeat:
		mt = TypeHeartbeat
	case *MessageEnd:
		mt = TypeEnd
	case *MessageLoginRequest:
		mt = TypeLoginRequest
	case *MessageUnsequencedData:
		mt = TypeUnsequencedData
	case *MessageClientHeartbeat:
		mt = TypeClientHeartbeat
	case *MessageLogout:
		mt = TypeLogout
	}
	errs.CheckE(m.getCommon().setHeader(mt))
	errs.CheckE(binary.Write(w, binary.BigEndian, m.getHeader()))
	n, err := w.Write(m.getCommon().Payload)
	errs.CheckE(err)
	errs.Check(n == len(m.getCommon().Payload))
	return
}
示例#2
0
文件: sbtcp.go 项目: ikravets/ev
func ReadMessage(r io.Reader) (m Message, err error) {
	defer errs.PassE(&err)
	var mc MessageCommon
	errs.CheckE(binary.Read(r, binary.BigEndian, &mc.Header))
	mc.Payload = make([]byte, mc.Header.Length-1)
	n, err := r.Read(mc.Payload)
	errs.CheckE(err)
	errs.Check(n == len(mc.Payload), n, len(mc.Payload))
	switch mc.Header.Type {
	case TypeDebug:
		m = &MessageDebug{}
	case TypeLoginAccepted:
		m = &MessageLoginAccepted{}
	case TypeLoginRejected:
		m = &MessageLoginRejected{}
	case TypeSequencedData:
		m = &MessageSequencedData{}
	case TypeHeartbeat:
		m = &MessageHeartbeat{}
	case TypeEnd:
		m = &MessageEnd{}
	case TypeLoginRequest:
		m = &MessageLoginRequest{}
	case TypeUnsequencedData:
		m = &MessageUnsequencedData{}
	case TypeClientHeartbeat:
		m = &MessageClientHeartbeat{}
	case TypeLogout:
		m = &MessageLogout{}
	}
	*m.getCommon() = mc
	errs.CheckE(m.decodePayload())
	return
}
示例#3
0
文件: subscr.go 项目: ikravets/ev
func (s *Subscr) SubscribeFromReader(rd io.Reader) (err error) {
	defer errs.PassE(&err)
	sc := bufio.NewScanner(rd)
	for sc.Scan() {
		text := sc.Text()
		var v uint64
		var b byte
		if _, err := fmt.Sscanf(text, "%c%v", &b, &v); err != nil {
			_, err = fmt.Sscanf(text, "%v", &v)
			errs.CheckE(err)
		}
		oid := packet.OptionIdFromUint64(v)
		if b == 'U' || b == 'u' || b == '!' {
			if s.autoSubscribe {
				s.stoplist[oid] = struct{}{}
			} else {
				s.Unsubscribe(oid)
			}
		} else {
			s.Subscribe(oid)
		}
	}
	errs.CheckE(sc.Err())
	return
}
示例#4
0
文件: bats.go 项目: ikravets/ev
func (c *conn) WriteMessageSimple(m Message) (err error) {
	defer errs.PassE(&err)
	c.pw.SyncStart()
	errs.CheckE(c.pw.WriteMessage(m))
	errs.CheckE(c.pw.Flush())
	return
}
示例#5
0
文件: inspect.go 项目: ikravets/ev
func (c *Config) Dump() (yamlDoc string, err error) {
	defer errs.PassE(&err)
	buf, err := yaml.Marshal(c.ast)
	errs.CheckE(err)
	yamlDoc = string(buf)
	return
}
示例#6
0
文件: bats.go 项目: ikravets/ev
func (mc *MessageCommon) setHeader(Type MessageType) (err error) {
	defer errs.PassE(&err)
	mc.Header.Type = Type
	mc.Header.Length = uint8(MessageLength[Type])
	errs.Check(mc.Header.Length != 0)
	return
}
示例#7
0
文件: nasdaq.go 项目: ikravets/ev
func createMoldPacket(startSeqNum, count int) (bs []byte, err error) {
	defer errs.PassE(&err)
	type moldUDP64 struct {
		Session        string `struc:"[10]byte"`
		SequenceNumber uint64
		MessageCount   uint16
	}
	type moldUDP64MessageBlock struct {
		MessageLength int16 `struc:"sizeof=Payload"`
		Payload       []uint8
	}

	errs.Check(startSeqNum >= 0)
	errs.Check(count >= 0 && count < 1000)
	mh := moldUDP64{
		Session:        "00TestSess",
		SequenceNumber: uint64(startSeqNum),
		MessageCount:   uint16(count),
	}
	var bb bytes.Buffer
	errs.CheckE(struc.Pack(&bb, &mh))
	for i := 0; i < count; i++ {
		mb := moldUDP64MessageBlock{
			Payload: generateIttoMessage(startSeqNum + i),
		}
		errs.CheckE(struc.Pack(&bb, &mb))
	}
	bs = bb.Bytes()
	return
}
示例#8
0
文件: memh2pcap.go 项目: ikravets/ev
func (m *memh2pcap) addOne(r io.Reader) (err error) {
	defer errs.PassE(&err)
	m.data.Reset()
	scanner := bufio.NewScanner(r)
	for i := 0; scanner.Scan(); i++ {
		v, err := strconv.ParseUint(scanner.Text(), 16, 64)
		errs.CheckE(err)
		line := make([]byte, 8)
		binary.LittleEndian.PutUint64(line, v)
		if i == 0 {
			// skip pseudo header (2 bytes)
			line = line[2:]
		}
		_, err = m.data.Write(line)
		errs.CheckE(err)
	}

	m.sb.Clear()
	b, err := m.sb.AppendBytes(m.data.Len())
	errs.CheckE(err)
	copy(b, m.data.Bytes())
	for _, l := range m.layers {
		errs.CheckE(l.SerializeTo(m.sb, m.so))
	}
	ci := gopacket.CaptureInfo{
		Timestamp:     time.Unix(int64(m.mold.SequenceNumber), 1),
		CaptureLength: len(m.sb.Bytes()),
		Length:        len(m.sb.Bytes()),
	}
	errs.CheckE(m.pw.WritePacket(ci, m.sb.Bytes()))
	m.mold.SequenceNumber++
	return
}
示例#9
0
文件: pcapsplit.go 项目: ikravets/ev
func (o *optionId) UnmarshalFlag(value string) (err error) {
	defer errs.PassE(&err)
	v, err := strconv.ParseUint(value, 0, 64)
	errs.CheckE(err)
	o.OptionId = packet.OptionIdFromUint64(v)
	return
}
示例#10
0
文件: efh_tool.go 项目: ikravets/ev
func (_ *efh_toolDevice) ReadRegister(bar int, addr uint64, size int) (value uint64, err error) {
	errs.PassE(&err)
	v, err := (exec.Command("efh_tool", "read", fmt.Sprint(bar), fmt.Sprintf("%0#16x", addr), fmt.Sprint(size))).Output()
	errs.CheckE(err)
	_, err = fmt.Sscan(string(v), &value)
	return
}
示例#11
0
文件: bats.go 项目: ikravets/ev
func (c *conn) ReadMessage() (m Message, err error) {
	defer errs.PassE(&err)
	for c.messageReader.N == 0 {
		errs.CheckE(c.readBsuHeader())
	}

	c.rbuf.Reset()
	var b [2]byte
	var n int
	_, err = io.ReadFull(&c.messageReader, b[:])
	errs.CheckE(err)
	log.Printf("rcv bytes %v", b)
	n, err = c.rbuf.Write(b[:])
	errs.CheckE(err)
	errs.Check(n == len(b))
	h := MessageHeader{
		Length: uint8(b[0]),
		Type:   MessageType(b[1]),
	}
	log.Printf("rcv header %#v", h)
	io.CopyN(&c.rbuf, &c.messageReader, int64(h.Length)-2)
	f := MessageFactory[h.Type]
	errs.Check(f != nil)
	m = f()
	errs.CheckE(binary.Read(&c.rbuf, binary.LittleEndian, m))
	log.Printf("rcv %#v\n", m)
	return
}
示例#12
0
文件: vsim.go 项目: ikravets/ev
func (s *SimLogger) PrintMessage(m efhMessage) (err error) {
	defer errs.PassE(&err)
	var bb bytes.Buffer
	errs.CheckE(binary.Write(&bb, binary.LittleEndian, m))
	if r := bb.Len() % 8; r > 0 {
		// pad to  multiple of 8 bytes
		z := make([]byte, 8)
		_, err = bb.Write(z[0 : 8-r])
		errs.CheckE(err)
	}

	for {
		var qw uint64
		if err := binary.Read(&bb, binary.LittleEndian, &qw); err != nil {
			if err == io.EOF {
				break
			}
			errs.CheckE(err)
		} else {
			s.printfln("DMATOHOST_DATA %016x", qw)
		}
	}
	s.printfln("DMATOHOST_TRAILER 00656e696c616b45")
	return
}
示例#13
0
文件: itto.go 项目: ikravets/ev
func (m *IttoMessageSeconds) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) (err error) {
	defer errs.PassE(&err)
	errs.CheckE(m.IttoMessageCommon.SerializeTo(b, opts))
	buf, err := b.AppendBytes(4)
	errs.CheckE(err)
	binary.BigEndian.PutUint32(buf, m.Second)
	return
}
示例#14
0
文件: mach.go 项目: ikravets/ev
func decodeMach(data []byte, p gopacket.PacketBuilder) (err error) {
	panic("FIXME")
	defer errs.PassE(&err)
	m := &Mach{}
	errs.CheckE(m.DecodeFromBytes(data, p))
	p.AddLayer(m)
	return p.NextDecoder(m.NextLayerType())
}
示例#15
0
文件: bats.go 项目: ikravets/ev
func (p *packetWriter) WriteMessage(m Message) (err error) {
	defer errs.PassE(&err)
	m.getCommon().setHeader(m.Type())
	errs.CheckE(binary.Write(&p.mb, binary.LittleEndian, m))
	p.bh.Count++
	errs.Check(p.bh.Count != 0)
	return
}
示例#16
0
文件: miax.go 项目: ikravets/ev
func (c *conn) WriteMessageSimple(m SesMMessage) (err error) {
	defer errs.PassE(&err)
	var b bytes.Buffer
	errs.CheckE(writeSesMHeader(&b, m))
	errs.CheckE(binary.Write(&b, binary.LittleEndian, m))
	_, err = c.rw.Write(b.Bytes())
	return
}
示例#17
0
文件: itto.go 项目: ikravets/ev
func (m *IttoMessageBaseReference) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) (err error) {
	defer errs.PassE(&err)
	errs.CheckE(m.IttoMessageCommon.SerializeTo(b, opts))
	buf, err := b.AppendBytes(8)
	errs.CheckE(err)
	binary.BigEndian.PutUint64(buf, m.BaseRefNum)
	return
}
示例#18
0
文件: tom.go 项目: ikravets/ev
func (m *TomMessageSystemTime) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) (err error) {
	defer errs.PassE(&err)
	errs.CheckE(m.TomMessageCommon.SerializeTo(b, opts))
	buf, err := b.AppendBytes(4)
	errs.CheckE(err)
	binary.LittleEndian.PutUint32(buf, m.Second)
	return
}
示例#19
0
文件: moldudp64.go 项目: ikravets/ev
func (m *MoldUDP64) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) (err error) {
	defer errs.PassE(&err)
	bytes, err := b.PrependBytes(20)
	errs.CheckE(err)
	copy(bytes[0:10], m.Session[0:10])
	binary.BigEndian.PutUint64(bytes[10:18], m.SequenceNumber)
	binary.BigEndian.PutUint16(bytes[18:20], m.MessageCount)
	return
}
示例#20
0
文件: miax.go 项目: ikravets/ev
func (c *conn) readSize() (err error) {
	defer errs.PassE(&err)
	errs.Check(c.messageReader.N == 0, c.messageReader.N)
	var s uint16
	errs.CheckE(binary.Read(c.rw, binary.LittleEndian, &s))
	log.Printf("rcv SesM size %d\n", s)
	c.messageReader = io.LimitedReader{R: c.rw, N: int64(s)}
	return
}
示例#21
0
文件: miax.go 项目: ikravets/ev
func (s *miaxMcastServer) start() (err error) {
	defer errs.PassE(&err)
	s.conn, err = net.DialUDP("udp", s.laddr, s.mcaddr)
	errs.CheckE(err)
	//	mconn := miax.NewConn(s.conn)
	s.mmsc = s.src.NewClient()
	go s.run()
	return
}
示例#22
0
文件: memh2pcap.go 项目: ikravets/ev
func (m *memh2pcap) addFile(filename string) (err error) {
	log.Printf("adding %s\n", filename)
	defer errs.PassE(&err)
	in, err := os.Open(filename)
	errs.CheckE(err)
	errs.CheckE(m.addOne(in))
	errs.CheckE(in.Close())
	return
}
示例#23
0
文件: efh_replay.go 项目: ikravets/ev
func (e *efhReplay) Run() (err error) {
	defer errs.PassE(&err)
	if e.EfhDump != "" {
		e.testEfhDump = "test_efh.dump"
	}
	defaultTestEfh := "/usr/libexec/test_efh"
	if e.Local {
		defaultTestEfh = os.ExpandEnv("$HOME/efh-install/bin/test_efh")
		e.testEfhArgs = append(e.testEfhArgs, "--load-fw", "/usr/share/efh/firmware/fw.bin")
	}
	if e.TestEfh == "" {
		e.TestEfh = defaultTestEfh
	}
	errs.CheckE(e.startTestEfh())
	errs.CheckE(e.startDumpReplay())
	func() {
		ticker := time.NewTicker(time.Second / 10)
		defer ticker.Stop()
		for {
			select {
			case <-e.testEfhDoneCh:
				fmt.Println()
				return
			case <-e.replayDoneCh:
				fmt.Printf("\rdone: 100%%   \n")
				time.Sleep(100 * time.Millisecond)
				return
			case <-ticker.C:
				if done, ok := e.replay.Progress(); ok {
					fmt.Printf("\rdone: %.1f%%", done*100)
				}
			}
		}
	}()
	errs.CheckE(e.stopDumpReplay())
	errs.CheckE(e.stopTestEfh())
	if e.testEfhDump != "" {
		var same bool
		same, err = e.diffAppDump()
		errs.CheckE(err)
		if !same {
			log.Printf("dumps differ")
			err = DumpsDifferError
		}
	}
	if e.RegConfig != nil {
		errs.CheckE(e.RegConfig.Probe())
		errs.CheckE(ioutil.WriteFile("registers", []byte(e.RegConfig.Report()), 0666))
		if e.RegConfig.IsBad() {
			log.Printf("register probe is bad")
			if err == nil {
				err = BadProbeError
			}
		}
	}
	return
}
示例#24
0
文件: pcapsplit.go 项目: ikravets/ev
func (s *Splitter) SplitByOption(oid packet.OptionId, fileName string) (err error) {
	defer errs.PassE(&err)
	outFile, err := os.Create(fileName)
	errs.CheckE(err)
	defer func() { errs.CheckE(outFile.Close()) }()
	confs := make(map[packet.OptionId]SplitByOptionsConfig)
	confs[oid] = SplitByOptionsConfig{Writer: outFile}
	return s.SplitByOptions(confs)
}
示例#25
0
文件: channels.go 项目: ikravets/ev
func (c *config) LoadFromReader(rd io.Reader) (err error) {
	defer errs.PassE(&err)
	all, err := ioutil.ReadAll(rd)
	errs.CheckE(err)
	for _, str := range strings.Fields(string(all)) {
		errs.CheckE(c.LoadFromStr(str))
	}
	return
}
示例#26
0
文件: bats.go 项目: ikravets/ev
func (s *spinServerConn) sendAll(start, end int) (err error) {
	defer errs.PassE(&err)
	log.Printf("spin send %d .. %d", start, end)
	for i := start; i < end; i++ {
		m := s.src.GetMessage(i)
		errs.CheckE(s.bconn.WriteMessageSimple(m))
	}
	log.Printf("spin send %d .. %d done", start, end)
	return
}
示例#27
0
文件: miax.go 项目: ikravets/ev
func (s *SesMServerConn) sendAll(start, end uint64) (err error) {
	defer errs.PassE(&err)
	log.Printf("sesm start retransm %d .. %d", start, end)
	for i := start; i <= end; i++ {
		m := s.src.GetMessage(i)
		errs.CheckE(s.mconn.WriteMachPacket(m))
	}
	log.Printf("sesm retransm %d .. %d done", start, end)
	return
}
示例#28
0
文件: miax.go 项目: ikravets/ev
func (p MachPacket) Write(w io.Writer) (err error) {
	defer errs.PassE(&err)
	var b bytes.Buffer
	errs.CheckE(binary.Write(&b, binary.LittleEndian, p.h))
	errs.CheckE(binary.Write(&b, binary.LittleEndian, p.m))
	//errs.CheckE(binary.Write(&b, binary.LittleEndian, p.h))
	//errs.CheckE(binary.Write(&b, binary.LittleEndian, p.m))
	_, err = w.Write(b.Bytes())
	errs.CheckE(err)
	return
}
示例#29
0
文件: moldudp64.go 项目: ikravets/ev
func (m *MoldUDP64MessageBlockChained) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) (err error) {
	defer errs.PassE(&err)
	payload := b.Bytes()
	bytes, err := b.PrependBytes(2)
	errs.CheckE(err)
	if opts.FixLengths {
		m.MessageLength = uint16(len(payload))
	}
	binary.BigEndian.PutUint16(bytes, uint16(m.MessageLength))
	return
}
示例#30
0
文件: efhsim.go 项目: ikravets/ev
func NewHashedOut(baseName string) (o *hashedOut, err error) {
	defer errs.PassE(&err)
	o = &hashedOut{}
	o.file, err = os.Create(baseName)
	errs.CheckE(err)
	o.md5file, err = os.Create(baseName + ".md5sum")
	errs.CheckE(err)
	o.md5sum = md5.New()
	o.mw = io.MultiWriter(o.file, o.md5sum)
	return
}