Ejemplo n.º 1
0
// getRingSlice returns a byte slice from the ring buffer given the head
// and tail of the ring segment AND the slice indexes for head and tail.
// That is, for head's byte slice, sliceStart is the a slice start index.
// For tail's byte slice, sliceEnd is the slice end index.
func getRingSlice(head, tail *types.Ring, sliceStart, sliceEnd int) []byte {
	var overlapBytes []byte
	if sliceStart < 0 || sliceEnd < 0 {
		log.Printf("sliceStart %d sliceEnd %d", sliceStart, sliceEnd)
		panic("getRingSlice: sliceStart < 0 || sliceEnd < 0")
	}
	if sliceStart >= len(head.Reassembly.Bytes) {
		panic(fmt.Sprintf("getRingSlice: sliceStart %d >= head len %d", sliceStart, len(head.Reassembly.Bytes)))
	}
	if sliceEnd > len(tail.Reassembly.Bytes) {
		panic("getRingSlice: impossible; sliceEnd is greater than ring segment")
	}
	if head == nil || tail == nil {
		panic("getRingSlice: head or tail is nil")
	}
	if head == tail {
		panic("getRingSlice: head == tail")
	}
	overlapBytes = append(overlapBytes, head.Reassembly.Bytes[sliceStart:]...)
	current := head.Next()
	for current.Reassembly.Seq != tail.Reassembly.Seq {
		overlapBytes = append(overlapBytes, current.Reassembly.Bytes...)
		current = current.Next()
	}
	overlapBytes = append(overlapBytes, tail.Reassembly.Bytes[:sliceEnd]...)
	return overlapBytes
}
Ejemplo n.º 2
0
func displayRingSummary(ringHeadPtr *types.Ring) {
	log.Print("displayRingSummary:")
	i := 0
	current := ringHeadPtr.Next()
	for current != ringHeadPtr {
		if current.Reassembly != nil {
			log.Printf("index: %d TCP.Seq %d Skip %d payload len %d\n", i, current.Reassembly.Seq, current.Reassembly.Skip, len(current.Reassembly.Bytes))
		} else {
			log.Printf("index: %d nil\n", i)
		}
		current = current.Next()
		i += 1
	}
}