Beispiel #1
0
func GetEntry(hash string) (interfaces.IEBEntry, error) {
	for i := 0; i < 100; i++ {
		raw, err := GetRaw(hash)
		if err != nil {
			fmt.Printf("got error %s\n", err)
			fmt.Printf("called getraw with %s\n", hash)
			fmt.Printf("got result %s\n", raw)

			continue
		}
		entry, err := entryBlock.UnmarshalEntry(raw)
		for err != nil { //just keep trying until it doesn't give an error
			fmt.Printf("got error %s\n", err)
			fmt.Printf("called entryBlock.UnmarshalEntry with %s\n", raw)
			fmt.Printf("got result %s\n", entry)
			//if we get an error like EOF, get the thing again after a short wait
			time.Sleep(20000 * time.Millisecond)
			raw, err = GetRaw(hash)
			if err != nil {
				continue
			}
			entry, err = entryBlock.UnmarshalEntry(raw)
		}
		return entry, nil
	}
	panic("Failed 100 times to get the data " + hash)
	return nil, nil
}
Beispiel #2
0
func attemptEntryUnmarshal(data []byte) (entry interfaces.IEBEntry, err error) {
	defer func() {
		if r := recover(); r != nil {
			err = fmt.Errorf("Bytes do not represent an entry")
		}
	}()

	entry, err = entryBlock.UnmarshalEntry(data)
	if err != nil {
		return nil, err
	}

	return entry, nil
}