Example #1
0
func (uc *UpdateCodec) findEntry(req *request) {
	r := new(received)
	r.Cache = req.Cache
	r.Entry = req.Entry
	r.Priority = req.Priority
	r.Data = cache.ReadEntry(int(req.Cache+2), int(req.Entry))
	uc.received <- r
}
Example #2
0
func processRequest(str string, client net.Conn) {
	if len(str) > 8 && str[:8] != "JAGGRAB " {
		fmt.Printf("Invalid request to JAGGRAB, disconnecting: %v", str)
		return
	}

	requested := str[8:]

	if requested[0:1] == "/" {
		requested = requested[1:]
	}

	crcidx := -1

	for i, codepoint := range requested {
		if codepoint >= '0' && codepoint <= '9' || codepoint == '-' {
			crcidx = i
			break
		}
	}

	file := requested[:crcidx]
	//crc := requested[crcidx:]

	//fmt.Printf("JAGGRAB request for: %v, File: %v, Expected CRC: %v\n", requested, file, crc)

	var data []byte

	switch {
	case file == "crc":
		data = make([]byte, 40)

		for i := 0; i < 10; i++ {
			c := cache.TitleCrc[i]
			b1, b2, b3, b4 := byte((c>>24)&0xff), byte((c>>16)&0xff), byte((c>>8)&0xff), byte(c&0xff)
			data[i*4+0] = b1
			data[i*4+1] = b2
			data[i*4+2] = b3
			data[i*4+3] = b4
		}
	default:
		id := fileMap[string(file)]
		data = cache.ReadEntry(1, id)

		//realCrc := cache.TitleCrc[id]
		// Todo: check CRC matches?
	}

	for total := 0; total < len(data); {
		written, err := client.Write(data)
		if err != nil {
			fmt.Printf("Error responding to JAGGRAB request, disconnecting: %v", err)
			return
		}
		total += written
	}
}