Documentation
¶
Overview ¶
Package config holds all Properties of dfget.
Index ¶
Constants ¶
const ( BackSourceReasonNone = 0 BackSourceReasonRegisterFail = 1 BackSourceReasonMd5NotMatch = 2 BackSourceReasonDownloadError = 3 BackSourceReasonNoSpace = 4 BackSourceReasonInitError = 5 BackSourceReasonWriteError = 6 BackSourceReasonHostSysError = 7 BackSourceReasonNodeEmpty = 8 BackSourceReasonSourceError = 10 BackSourceReasonUserSpecified = 100 ForceNotBackSourceAddition = 1000 )
the reason of backing to source
const ( PatternP2P = "p2p" PatternCDN = "cdn" PatternSource = "source" )
download pattern
const ( DefaultYamlConfigFile = "/etc/dragonfly/dfget.yml" DefaultIniConfigFile = "/etc/dragonfly.conf" DefaultNode = "127.0.0.1" DefaultLocalLimit = 20 * rate.MB DefaultMinRate = 64 * rate.KB DefaultClientQueueSize = 6 DefaultSupernodeWeight = 1 )
properties
const ( StrRange = "Range" StrContentLength = "Content-Length" StrContentType = "Content-Type" StrUserAgent = "User-Agent" StrTaskFileName = "taskFileName" StrClientID = "cid" StrTaskID = "taskID" StrSuperNode = "superNode" StrRateLimit = "rateLimit" StrPieceNum = "pieceNum" StrPieceSize = "pieceSize" StrDataDir = "dataDir" StrTotalLimit = "totalLimit" StrCDNSource = "cdnSource" StrBytes = "bytes" )
http headers
const ( // PieceHeadSize every piece starts with a piece head which has 4 bytes, // its value is: // real data size | (piece size << 4) // And it's written with big-endian into the first four bytes of piece data. PieceHeadSize = 4 // PieceTailSize every piece ends with a piece tail which has 1 byte, // its value is: 0x7f PieceTailSize = 1 // PieceMetaSize piece meta is constructed with piece head and tail, // its size is 5 bytes. PieceMetaSize = PieceHeadSize + PieceTailSize // PieceTailChar the value of piece tail PieceTailChar = byte(0x7f) )
piece meta
const ( DefaultTimestampFormat = "2006-01-02 15:04:05" SchemaHTTP = "http" ServerPortLowerLimit = 15000 ServerPortUpperLimit = 65000 RangeNotSatisfiableDesc = "range not satisfiable" AddrUsedDesc = "address already in use" PeerHTTPPathPrefix = "/peer/file/" CDNPathPrefix = "/qtdown/" LocalHTTPPathCheck = "/check/" LocalHTTPPathClient = "/client/" LocalHTTPPathRate = "/rate/" LocalHTTPPing = "/server/ping" DataExpireTime = 3 * time.Minute ServerAliveTime = 5 * time.Minute DefaultDownloadTimeout = 5 * time.Minute DefaultSupernodePort = 8002 )
others
const ( // CodeLaunchServerError represents failed to launch a peer server. CodeLaunchServerError = 1100 + iota // CodePrepareError represents failed to prepare before downloading. CodePrepareError // CodeGetUserError represents failed to get current user. CodeGetUserError // CodeRegisterError represents failed to register to supernode. CodeRegisterError // CodeDownloadError represents failed to download file. CodeDownloadError )
errors code
const (
RangeSeparator = "-"
)
Variables ¶
This section is empty.
Functions ¶
func AssertConfig ¶ added in v0.3.0
AssertConfig checks the config and return errors.
func NodeWeightSlice2StringSlice ¶ added in v1.0.1
func NodeWeightSlice2StringSlice(supernodes []*NodeWeight) []string
NodeWeightSlice2StringSlice parses nodeWeight slice to string slice. It takes the NodeWeight.Node as the value and every value will be appended the corresponding NodeWeight.Weight times.
Types ¶
type Config ¶ added in v0.3.0
type Config struct {
// URL download URL.
URL string `json:"url"`
// Output full output path.
Output string `json:"output"`
// Timeout download timeout(second).
Timeout time.Duration `json:"timeout,omitempty"`
// Md5 expected file md5.
Md5 string `json:"md5,omitempty"`
// Identifier identify download task, it is available merely when md5 param not exist.
Identifier string `json:"identifier,omitempty"`
// CallSystem system name that executes dfget.
CallSystem string `json:"callSystem,omitempty"`
// Pattern download pattern, must be 'p2p' or 'cdn' or 'source',
// default:`p2p`.
Pattern string `json:"pattern,omitempty"`
// CA certificate to verify when supernode interact with the source.
Cacerts []string `json:"cacert,omitempty"`
// Filter filter some query params of url, use char '&' to separate different params.
// eg: -f 'key&sign' will filter 'key' and 'sign' query param.
// in this way, different urls correspond one same download task that can use p2p mode.
Filter []string `json:"filter,omitempty"`
// Header of http request.
// eg: --header='Accept: *' --header='Host: abc'.
Header []string `json:"header,omitempty"`
// Notbs indicates whether to not back source to download when p2p fails.
Notbs bool `json:"notbs,omitempty"`
// DFDaemon indicates whether the caller is from dfdaemon
DFDaemon bool `json:"dfdaemon,omitempty"`
// Insecure indicates whether skip secure verify when supernode interact with the source.
Insecure bool `json:"insecure,omitempty"`
// ShowBar shows progress bar, it's conflict with `--console`.
ShowBar bool `json:"showBar,omitempty"`
// Console shows log on console, it's conflict with `--showbar`.
Console bool `json:"console,omitempty"`
// Verbose indicates whether to be verbose.
// If set true, log level will be 'debug'.
Verbose bool `json:"verbose,omitempty"`
// Nodes specify supernodes.
Nodes []string `json:"-"`
// Start time.
StartTime time.Time `json:"-"`
// Sign the value is 'Pid + float64(time.Now().UnixNano())/float64(time.Second) format: "%d-%.3f"'.
// It is unique for downloading task, and is used for debugging.
Sign string `json:"-"`
// Username of the system currently logged in.
User string `json:"-"`
// Config file paths,
// default:["/etc/dragonfly/dfget.yml","/etc/dragonfly.conf"].
//
// NOTE: It is recommended to use `/etc/dragonfly/dfget.yml` as default,
// and the `/etc/dragonfly.conf` is just to ensure compatibility with previous versions.
ConfigFiles []string `json:"-"`
// RV stores the variables that are initialized and used at downloading task executing.
RV RuntimeVariable `json:"-"`
// The reason of backing to source.
BackSourceReason int `json:"-"`
// Embedded Properties holds all configurable properties.
Properties
}
Config holds all the runtime config information.
type MetaData ¶ added in v0.3.0
type MetaData struct {
// ServicePort the TCP port on which the file upload service listens.
ServicePort int `json:"servicePort"`
// MetaPath the path of meta file.
MetaPath string `json:"-"`
}
MetaData stores meta information that should be persisted.
func NewMetaData ¶ added in v0.3.0
NewMetaData creates a MetaData instance.
type NodeWeight ¶ added in v1.0.1
func GetDefaultSupernodesValue ¶ added in v1.0.0
func GetDefaultSupernodesValue() []*NodeWeight
GetDefaultSupernodesValue returns the default value of supernodes. default: ["127.0.0.1:8002=1"]
func ParseNodesSlice ¶ added in v1.0.0
func ParseNodesSlice(value []string) ([]*NodeWeight, error)
ParseNodesSlice parses the value in string slice type to []*NodeWeight.
func ParseNodesString ¶ added in v1.0.0
func ParseNodesString(value string) ([]*NodeWeight, error)
ParseNodesString parses the value in string type to []*NodeWeight.
func (*NodeWeight) MarshalJSON ¶ added in v1.0.1
func (nw *NodeWeight) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (*NodeWeight) MarshalYAML ¶ added in v1.0.1
func (nw *NodeWeight) MarshalYAML() (interface{}, error)
MarshalYAML implements the yaml.Marshaler interface.
func (*NodeWeight) UnmarshalJSON ¶ added in v1.0.1
func (nw *NodeWeight) UnmarshalJSON(b []byte) error
UnmarshalJSON implements the json.Unmarshaler interface.
func (*NodeWeight) UnmarshalYAML ¶ added in v1.0.1
func (nw *NodeWeight) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML implements the yaml.Unmarshaler interface.
type Properties ¶
type Properties struct {
// Supernodes specify supernodes with weight.
// The type of weight must be integer.
// All weights will be divided by the greatest common divisor in the end.
//
// E.g. ["192.168.33.21=1", "192.168.33.22=2"]
Supernodes []*NodeWeight `yaml:"nodes,omitempty" json:"nodes,omitempty"`
// LocalLimit rate limit about a single download task, format: G(B)/g/M(B)/m/K(B)/k/B
// pure number will also be parsed as Byte.
LocalLimit rate.Rate `yaml:"localLimit,omitempty" json:"localLimit,omitempty"`
// Minimal rate about a single download task, format: G(B)/g/M(B)/m/K(B)/k/B
// pure number will also be parsed as Byte.
MinRate rate.Rate `yaml:"minRate,omitempty" json:"minRate,omitempty"`
// TotalLimit rate limit about the whole host, format: G(B)/g/M(B)/m/K(B)/k/B
// pure number will also be parsed as Byte.
TotalLimit rate.Rate `yaml:"totalLimit,omitempty" json:"totalLimit,omitempty"`
// ClientQueueSize is the size of client queue
// which controls the number of pieces that can be processed simultaneously.
// It is only useful when the Pattern equals "source".
// The default value is 6.
ClientQueueSize int `yaml:"clientQueueSize" json:"clientQueueSize,omitempty"`
// WorkHome work home path,
// default: `$HOME/.small-dragonfly`.
WorkHome string `yaml:"workHome" json:"workHome,omitempty"`
LogConfig dflog.LogConfig `yaml:"logConfig" json:"logConfig"`
}
Properties holds all configurable Properties. Support INI(or conf) and YAML(since 0.3.0). Before 0.3.0, only support INI config and only have one property(node):
[node] address=127.0.0.1,10.10.10.1
Since 0.2.0, the INI config is just to be compatible with previous versions. The YAML config will have more properties:
nodes:
- 127.0.0.1=1
- 10.10.10.1:8002=2
localLimit: 20M
totalLimit: 20M
clientQueueSize: 6
func NewProperties ¶
func NewProperties() *Properties
NewProperties creates a new properties with default values.
func (*Properties) Load ¶
func (p *Properties) Load(path string) error
Load loads properties from config file.
func (*Properties) String ¶
func (p *Properties) String() string
type RuntimeVariable ¶ added in v0.3.0
type RuntimeVariable struct {
// MetaPath specify the path of meta file which store the meta info of the peer that should be persisted.
// �Only server port information is stored currently.
MetaPath string
// SystemDataDir specifies a default directory to store temporary files.
SystemDataDir string
// DataDir specifies a directory to store temporary files.
// For now, the value of `DataDir` always equals `SystemDataDir`,
// and there is no difference between them.
// TODO: If there is insufficient disk space, we should set it to the `TargetDir`.
DataDir string
// RealTarget specifies the full target path whose value is equal to the `Output`.
RealTarget string
// StreamMode specifies that all pieces will be wrote to a Pipe, currently only support cdn mode.
// when StreamMode is true, all data will write directly.
// the mode is prepared for this issue https://github.com/dragonflyoss/Dragonfly/issues/1164
// TODO: support p2p mode
StreamMode bool
// TargetDir is the directory of the RealTarget path.
TargetDir string
// TempTarget is a temp file path that try to determine
// whether the `TargetDir` and the `DataDir` belong to the same disk by making a hard link.
TempTarget string
// Cid means the client ID which is a string composed of `localIP + "-" + sign` which represents a peer node.
// NOTE: Multiple dfget processes on the same peer have different CIDs.
Cid string
// TaskURL is generated from rawURL which may contains some queries or parameter.
// Dfget will filter some volatile queries such as timestamps via --filter parameter of dfget.
TaskURL string
// TaskFileName is a string composed of `the last element of RealTarget path + "-" + sign`.
TaskFileName string
// LocalIP is the native IP which can connect supernode successfully.
LocalIP string
// PeerPort is the TCP port on which the file upload service listens as a peer node.
PeerPort int
// FileLength the length of the file to download.
FileLength int64
// DataExpireTime specifies the caching duration for which
// cached files keep no accessed by any process.
// After this period, the cached files will be deleted.
DataExpireTime time.Duration
// ServerAliveTime specifies the alive duration for which
// uploader keeps no accessing by any uploading requests.
// After this period, the uploader will automatically exit.
ServerAliveTime time.Duration
}
RuntimeVariable stores the variables that are initialized and used at downloading task executing.
func (*RuntimeVariable) String ¶ added in v0.3.0
func (rv *RuntimeVariable) String() string
type SupernodesValue ¶ added in v1.0.0
type SupernodesValue struct {
Nodes *[]*NodeWeight
}
func NewSupernodesValue ¶ added in v1.0.0
func NewSupernodesValue(p *[]*NodeWeight, val []*NodeWeight) *SupernodesValue
func (*SupernodesValue) Set ¶ added in v1.0.0
func (sv *SupernodesValue) Set(value string) error
Set implements the pflag.Value interface.
func (*SupernodesValue) String ¶ added in v1.0.0
func (sv *SupernodesValue) String() string
String implements the pflag.Value interface.
func (*SupernodesValue) Type ¶ added in v1.0.0
func (sv *SupernodesValue) Type() string
Type implements the pflag.Value interface.