package wire import ( "net/netip" "regexp" ) // How the person API shows Research (slice R3; slice R5 renders it): the // site inventory card and a Research step's result on the task. These // are read shapes only; nothing here travels to a runner. // CardInventoryView is what a research_inventory card shows: the primary // it is about and every address Equipo detected for it (the addresses // its interfaces report and the one the instance saw it connect from). // Confirm records them, so Research never fetches from them. type CardInventoryView struct { RunnerID string `json:"runner_id"` Addresses []string `json:"addresses"` } // StepResearch is a Research step's result on the task's read shape: the // findings of its latest done attempt (or the "ended without findings" // gap), its fetch log, and the images it kept. Each image is served at // GET /api/v1/tasks/{task}/files/{id}. type StepResearch struct { Attempt int64 `json:"attempt"` Findings ResearchFindings `json:"findings"` Fetches []ResearchFetch `json:"fetches"` Images []StepResearchImage `json:"images"` } // StepResearchImage is one kept image: ID is the task file's id, ImageID // the id the findings cite. type StepResearchImage struct { ID string `json:"id"` ImageID string `json:"image_id"` SourceID string `json:"source_id"` Role string `json:"role"` Description string `json:"description"` Size int64 `json:"size"` Width int `json:"width"` Height int `json:"height"` } // ResearchOriginExpanded is a fetch log line's origin for a page or image // the fetcher reached from an approved source (Parent names it). const ResearchOriginExpanded = "expanded" // MaxKeptSide bounds a kept image's width and height, as // ValidResearchImage does. const MaxKeptSide = 2048 // ResearchNoFindingsGap is the gap a Research step's findings hold when // it ended without valid findings (Research spec ยง5). const ResearchNoFindingsGap = "Research ended without findings" // NoFindings is the findings document of a Research step that ended // without valid findings. func NoFindings() ResearchFindings { return ResearchFindings{Facts: []ResearchFact{}, Images: []string{}, Gaps: []string{ResearchNoFindingsGap}} } // ValidSHA256 is a lowercase hex SHA-256. func ValidSHA256(s string) bool { return sha256Pattern.MatchString(s) } var fetchWord = regexp.MustCompile(`^[a-z][a-z0-9_]{0,31}$`) // ValidFetchWord is a fetch log line's origin or reason: a short code. func ValidFetchWord(s string) bool { return fetchWord.MatchString(s) } // ResearchPrefixes are the site inventory prefixes an owner's Confirm // records for one detected address: the address itself (/32 or /128), // and for IPv6 its /64 too. Nil for anything ValidResearchAddress // refuses. func ResearchPrefixes(addr string) []string { if !ValidResearchAddress(addr) { return nil } a := netip.MustParseAddr(addr) out := []string{netip.PrefixFrom(a, a.BitLen()).String()} if a.Is6() { p, _ := a.Prefix(64) out = append(out, p.String()) } return out }