Documentation
¶
Index ¶
- Constants
- Variables
- func GetDigest(r io.Reader, digestAlgorithm DigestAlgorithm) (string, error)
- func GetNextIP(availableIPs *availableIPs) net.IP
- func IsDigestSupported(algorithm string) bool
- func MustCompressionTypeFromString(s string) compressionType
- func WithFeedbackChannel(ctx context.Context, feedbackChan chan FeedbackEvent) context.Context
- func WithSaveChannel(ctx context.Context, ch chan bool) context.Context
- func WithWrappedConnection(ctx context.Context, wrappedConnChan chan *CustomConnection) context.Context
- type Compressor
- type ConnPoolStats
- type CustomConnection
- type CustomHTTPClient
- func (c *CustomHTTPClient) Close() error
- func (c *CustomHTTPClient) CloseIdleConnections()
- func (c *CustomHTTPClient) Do(req *http.Request) (*http.Response, error)
- func (c *CustomHTTPClient) Get(url string) (*http.Response, error)
- func (c *CustomHTTPClient) GetConnPoolStats() *ConnPoolStats
- func (c *CustomHTTPClient) Head(url string) (*http.Response, error)
- func (c *CustomHTTPClient) Post(url, contentType string, body interface{}) (*http.Response, error)
- func (c *CustomHTTPClient) WriteRecord(WARCTargetURI, WARCType, contentType, payloadString string, ...)
- type DedupeOptions
- type DigestAlgorithm
- type Error
- type FeedbackEvent
- type GzipReaderInterface
- type GzipWriterInterface
- type HTTPClientSettings
- type Header
- type ReadOpts
- type Reader
- type Record
- type RecordBatch
- type RecordEvent
- type RecordInfo
- type RotatorSettings
- type TLSProfile
- type WaitGroupWithCount
- type Writer
Constants ¶
const ( ContextKeyFeedback contextKey = "feedback" ContextKeyWrappedConn contextKey = "wrappedConn" ContextKeySave contextKey = "save" )
const ( CompressionNone = compressionType("none") CompressionGzip = compressionType("gzip") CompressionZstd = compressionType("zstd") )
Variables ¶
var ( IPv6 *availableIPs IPv4 *availableIPs )
var ( // Create a couple of counters for tracking various stats DataTotal atomic.Int64 CDXDedupeTotalBytes atomic.Int64 DoppelgangerDedupeTotalBytes atomic.Int64 LocalDedupeTotalBytes atomic.Int64 CDXDedupeTotal atomic.Int64 DoppelgangerDedupeTotal atomic.Int64 LocalDedupeTotal atomic.Int64 )
var CompressionTypes = []compressionType{CompressionNone, CompressionGzip, CompressionZstd}
var DedupeHTTPClient = http.Client{ Timeout: 10 * time.Second, Transport: &http.Transport{ Dial: (&net.Dialer{ Timeout: 5 * time.Second, }).Dial, TLSHandshakeTimeout: 5 * time.Second, }, }
var ErrUnknownDigestAlgorithm = errors.New("unknown digest algorithm")
Functions ¶
func IsDigestSupported ¶
func MustCompressionTypeFromString ¶
func MustCompressionTypeFromString(s string) compressionType
func WithFeedbackChannel ¶
func WithFeedbackChannel(ctx context.Context, feedbackChan chan FeedbackEvent) context.Context
func WithWrappedConnection ¶
func WithWrappedConnection(ctx context.Context, wrappedConnChan chan *CustomConnection) context.Context
Types ¶
type Compressor ¶
type ConnPoolStats ¶
type CustomConnection ¶
type CustomConnection struct {
net.Conn
io.Reader
io.Writer
sync.WaitGroup
// contains filtered or unexported fields
}
CustomConnection is kept for backward compatibility with WithWrappedConnection.
func (*CustomConnection) Close ¶
func (cc *CustomConnection) Close() error
func (*CustomConnection) CloseWithError ¶
func (cc *CustomConnection) CloseWithError(err error) error
type CustomHTTPClient ¶
type CustomHTTPClient struct {
WaitGroup *WaitGroupWithCount
ErrChan chan *Error
WARCWriter chan *RecordBatch
TempDir string
TLSHandshakeTimeout time.Duration
ConnReadDeadline time.Duration
MaxReadBeforeTruncate int // todo
DigestAlgorithm DigestAlgorithm
DataTotal *atomic.Int64
DecompressBody bool
CDXDedupeTotalBytes *atomic.Int64
DoppelgangerDedupeTotalBytes *atomic.Int64
LocalDedupeTotalBytes *atomic.Int64
CDXDedupeTotal *atomic.Int64
DoppelgangerDedupeTotal *atomic.Int64
LocalDedupeTotal *atomic.Int64
// contains filtered or unexported fields
}
func NewWARCWritingHTTPClient ¶
func NewWARCWritingHTTPClient(HTTPClientSettings HTTPClientSettings) (httpClient *CustomHTTPClient, err error)
func (*CustomHTTPClient) Close ¶
func (c *CustomHTTPClient) Close() error
func (*CustomHTTPClient) CloseIdleConnections ¶
func (c *CustomHTTPClient) CloseIdleConnections()
func (*CustomHTTPClient) GetConnPoolStats ¶
func (c *CustomHTTPClient) GetConnPoolStats() *ConnPoolStats
func (*CustomHTTPClient) Post ¶
func (c *CustomHTTPClient) Post(url, contentType string, body interface{}) (*http.Response, error)
func (*CustomHTTPClient) WriteRecord ¶
func (c *CustomHTTPClient) WriteRecord(WARCTargetURI, WARCType, contentType, payloadString string, payloadReader io.Reader)
type DedupeOptions ¶
type DigestAlgorithm ¶
type DigestAlgorithm int
const ( SHA1 DigestAlgorithm = iota // According to IIPC, lowercase base 16 is the "popular" encoding for SHA256 SHA256Base16 SHA256Base32 BLAKE3 )
func GetDigestFromPrefix ¶
func GetDigestFromPrefix(prefix string) DigestAlgorithm
type FeedbackEvent ¶
type FeedbackEvent []RecordEvent // WARC-Record-ID header values of the records that have been written
type GzipReaderInterface ¶
type GzipReaderInterface interface {
io.ReadCloser
Multistream(enable bool)
Reset(r io.Reader) error
}
GzipReaderInterface defines the interface for gzip readers This allows us to switch between standard gzip and klauspost gzip based on build tags
type GzipWriterInterface ¶
type GzipWriterInterface interface {
io.WriteCloser
Flush() error
Reset(w io.Writer)
}
GzipWriterInterface defines the interface for gzip writers This allows us to switch between standard gzip and klauspost gzip based on build tags
type HTTPClientSettings ¶
type HTTPClientSettings struct {
RotatorSettings *RotatorSettings
TempDir string
DNSServers []string
DNSFallback *dns.ClientConfig
DedupeOptions DedupeOptions
DialTimeout time.Duration
ResponseHeaderTimeout time.Duration
DNSResolutionTimeout time.Duration
DNSRecordsTTL time.Duration
DNSCacheSize int
DNSConcurrency int
TLSHandshakeTimeout time.Duration
ConnReadDeadline time.Duration
MaxReadBeforeTruncate int // todo
DecompressBody bool
FollowRedirects bool
InsecureSkipVerifyCerts bool
RandomLocalIP bool
DisableIPv4 bool
DisableIPv6 bool
IPv6AnyIP bool
DigestAlgorithm DigestAlgorithm
EnableKeepAlive bool
DefaultUserAgent string
ClientProfile profiles.ClientProfile
RandomTLSExtensionOrder bool
MaxIdleConns int
MaxIdleConnsPerHost int
IdleConnTimeout time.Duration
EnableHTTP2 bool
EnableHTTP3 bool
ForceProtocol string // "http/1.1", "h2", "h3"
}
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader stores the bufio.Reader and gzip.Reader for a WARC file
type Record ¶
type Record struct {
RecordInfo
Content spooledtempfile.ReadWriteSeekCloser
}
Record represents a WARC record.
type RecordBatch ¶
type RecordBatch struct {
FeedbackChan chan FeedbackEvent
CaptureTime string
Records []*Record
}
RecordBatch is a structure that contains a bunch of records to be written at the same time, and a common capture timestamp. FeedbackChan is used to signal when the records have been written.
func NewRecordBatch ¶
func NewRecordBatch(feedbackChan chan FeedbackEvent) *RecordBatch
NewRecordBatch creates a record batch, it also initialize the capture time.
type RecordEvent ¶
type RecordEvent struct {
RecordInfo
WARCFilename string // WARC filename, no .open extension
}
a record that has been written to a WARC file.
type RecordInfo ¶
type RecordInfo struct {
Header Header
Offset int64 // Offset of the record start (-1 if WARC file type is not supported yet)
Size int64 // COMPRESSED size of the record (gzip member): header + deflate data + trailer. (-1 if WARC file type is not supported yet)
Version string // WARC/1.0, WARC/1.1 ...
}
type RotatorSettings ¶
type RotatorSettings struct {
// Content of the warcinfo record that will be written
// to all WARC files
WarcinfoContent Header
// Prefix used for WARC filenames, WARC 1.1 specifications
// recommend to name files this way:
// Prefix-Timestamp-Serial-Crawlhost.warc.gz
Prefix string
// Compression algorithm to use
Compression compressionType
// Path to a ZSTD compression dictionary to embed (and use) in .warc.zst files
CompressionDictionary string
// Directory where the created WARC files will be stored,
// default will be the current directory
OutputDirectory string
// WARCSize is in Megabytes
WARCSize float64
// WARCWriterPoolSize defines the number of parallel WARC writers
WARCWriterPoolSize int
// You can get warc filename from this channel after each WARC file is written and closed and renamed to non-temp name.
// - `nil` to disable
// - it's your responsibility to close this channel
WARCFilenameFeedbackChan chan string
// contains filtered or unexported fields
}
RotatorSettings is used to store the settings needed by recordWriter to write WARC files
func NewRotatorSettings ¶
func NewRotatorSettings() *RotatorSettings
NewRotatorSettings creates a RotatorSettings structure and initialize it with default values
func (*RotatorSettings) NewWARCRotator ¶
func (s *RotatorSettings) NewWARCRotator() (recordWriterChan chan *RecordBatch, doneChannels []chan bool, err error)
NewWARCRotator creates and return a channel that can be used to communicate records to be written to WARC files to the recordWriter function running in a goroutine
type TLSProfile ¶
type TLSProfile struct {
// contains filtered or unexported fields
}
func DefaultTLSProfile ¶
func DefaultTLSProfile() *TLSProfile
func NewTLSProfile ¶
func NewTLSProfile(profile profiles.ClientProfile, randomExtOrder bool) *TLSProfile
type WaitGroupWithCount ¶
func (*WaitGroupWithCount) Add ¶
func (wg *WaitGroupWithCount) Add(delta int)
func (*WaitGroupWithCount) Done ¶
func (wg *WaitGroupWithCount) Done()
func (*WaitGroupWithCount) Size ¶
func (wg *WaitGroupWithCount) Size() int
type Writer ¶
type Writer struct {
Compressor Compressor
BufWriter *bufio.Writer
FileName string
DigestAlgorithm DigestAlgorithm
ParallelGZIP bool
}
Writer writes WARC records to WARC files.
func NewWriter ¶
func NewWriter(writer io.Writer, fileName string, digestAlgorithm DigestAlgorithm, compression compressionType, newFileCreation bool, dictionary []byte) (*Writer, error)
NewWriter creates a new WARC writer.
func (*Writer) FlushAndCloseCompressor ¶
Close will flush the final output and close the stream. The function will block until everything has been written. The Compressor can still be re-used after calling this. If the Compressor is nil, this will just flush the Writer.BufWriter.
func (*Writer) Reset ¶
reset resets the compressed writer to write to a new output. This reuses the encoder's internal buffers.
func (*Writer) WriteInfoRecord ¶
WriteInfoRecord method can be used to write an information record to the WARC file and flush the data
func (*Writer) WriteRecord ¶
WriteRecord writes a record to the underlying WARC file and flushes the data. A record consists of a version string, the record header followed by a record content block and two newlines:
Version CLRF Header-Key: Header-Value CLRF CLRF Content CLRF CLRF