Skip to content

Commit

Permalink
use new path function
Browse files Browse the repository at this point in the history
  • Loading branch information
aditsachde committed Aug 3, 2024
1 parent 96b62a2 commit 1e53b4e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 8 deletions.
6 changes: 3 additions & 3 deletions internal/ctmonitor/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ func (f *Fetch) getSth(ctx context.Context) (ct.SignedTreeHead, error) {
func (f *Fetch) getTile(ctx context.Context, tile tlog.Tile) ([]byte, error) {
fallbackWidth := tile.W
tile.W = sunlight.TileWidth
resp, notfound, err := f.s.Get(ctx, tile.Path())
resp, notfound, err := f.s.Get(ctx, sunlight.Path(tile))
// In case the tile is not found, try to fetch the partial tile
if notfound == true {
if notfound {
if fallbackWidth != sunlight.TileWidth {
tile.W = fallbackWidth
return f.get(ctx, tile.Path())
return f.get(ctx, sunlight.Path(tile))
}
}
return resp, err
Expand Down
2 changes: 1 addition & 1 deletion internal/ctmonitor/logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func hashreader(ctx context.Context, f Fetch, fallbackTreeSize int64) tlog.HashR
// and then fall back to the width actually specified in the tile.
data, err := f.getTile(ctx, tile)
if err != nil {
return nil, fmt.Errorf("failed to fetch tile %s: %w (fallback %s)", tile.Path(), err, finalTile.Path())
return nil, fmt.Errorf("failed to fetch tile %s: %w (fallback %s)", sunlight.Path(tile), err, sunlight.Path(finalTile))
}
hash, err := tlog.HashFromTile(tile, data, index)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/ctsubmit/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Bucket struct {
// --------------------------------------------------------------------------------------------

func (b *Bucket) SetTile(ctx context.Context, tile tlog.Tile, data []byte) error {
return b.S.Set(ctx, tile.Path(), data)
return b.S.Set(ctx, sunlight.Path(tile), data)
}

func (b *Bucket) SetSth(ctx context.Context, data []byte) error {
Expand Down
2 changes: 1 addition & 1 deletion internal/ctsubmit/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func LoadLog(ctx context.Context, kvpath, consulAddress string) (*Log, error) {
// the data tile is the same as the level zero tile, with L -1
dataTile.Tile.L = -1

dataTileBytes, err := bucket.S.Get(ctx, dataTile.Path())
dataTileBytes, err := bucket.S.Get(ctx, sunlight.Path(dataTile.Tile))
if err != nil {
return nil, fmt.Errorf("unable to fetch data tile: %v", err)
}
Expand Down
33 changes: 32 additions & 1 deletion internal/sunlight/tile_ol.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ package sunlight

import (
"fmt"
"github.com/google/certificate-transparency-go/x509"
"math"

"github.com/google/certificate-transparency-go/x509"

"golang.org/x/crypto/cryptobyte"
"golang.org/x/mod/sumdb/tlog"
)

const TileHeight = 8
Expand Down Expand Up @@ -233,3 +235,32 @@ func addExtensions(b *cryptobyte.Builder, leafIndex uint64) {
b.AddBytes(ext)
})
}

// To limit the size of any particular directory listing,
// we encode the (possibly very large) number N
// by encoding three digits at a time.
// For example, 123456789 encodes as x123/x456/789.
// Each directory has at most 1000 each xNNN, NNN, and NNN.p children,
// so there are at most 3000 entries in any one directory.
const pathBase = 1000

// Path returns a tile coordinate path describing t.
func Path(t tlog.Tile) string {
n := t.N
nStr := fmt.Sprintf("%03d", n%pathBase)
for n >= pathBase {
n /= pathBase
nStr = fmt.Sprintf("x%03d/%s", n%pathBase, nStr)
}
pStr := ""
if t.W != 1<<uint(t.H) {
pStr = fmt.Sprintf(".p/%d", t.W)
}
var L string
if t.L == -1 {
L = "data"
} else {
L = fmt.Sprintf("%d", t.L)
}
return fmt.Sprintf("tile/%s/%s%s", L, nStr, pStr)
}
2 changes: 1 addition & 1 deletion internal/sunlight/tile_reader_ol.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (r *TileReader) Height() int {

func (r *TileReader) ReadTiles(tiles []tlog.Tile) (data [][]byte, err error) {
for _, t := range tiles {
b, err := r.Fetch(t.Path())
b, err := r.Fetch(Path(t))
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 1e53b4e

Please sign in to comment.