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 * 1024 * 1024 DefaultClientQueueSize = 6 )
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" 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 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
Variables ¶
This section is empty.
Functions ¶
func AssertConfig ¶ added in v0.3.0
AssertConfig checks the config and return errors.
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"` // LocalLimit rate limit about a single download task,format: 20M/m/K/k. LocalLimit int `json:"localLimit,omitempty"` // TotalLimit rate limit about the whole host,format: 20M/m/K/k. TotalLimit int `json:"totalLimit,omitempty"` // Timeout download timeout(second). Timeout int `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"` // 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"` // Node specify supernodes. Node []string `json:"node,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"` // Version show version. Version bool `json:"version,omitempty"` // ShowBar show progress bar, it's conflict with `--console`. ShowBar bool `json:"showBar,omitempty"` // Console show 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"` // Help show help information. Help bool `json:"help,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 not equals "source". // The default value is 6. ClientQueueSize int `json:"clientQueueSize,omitempty"` // Start time. StartTime time.Time `json:"startTime"` // 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:"sign"` // Username of the system currently logged in. User string `json:"user"` // WorkHome work home path, // default: `$HOME/.small-dragonfly`. WorkHome string `json:"workHome"` // 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:"configFile"` // 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:"-"` }
Config holds all the runtime config information.
type MetaData ¶ added in v0.3.0
type MetaData struct { // ServicePort the 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 create a MetaData instance.
type Properties ¶
type Properties struct { // Nodes specify supernodes. Nodes []string `yaml:"nodes"` // LocalLimit rate limit about a single download task,format: 20M/m/K/k. LocalLimit int `yaml:"localLimit"` // TotalLimit rate limit about the whole host,format: 20M/m/K/k. TotalLimit int `yaml:"totalLimit"` // 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"` }
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 - 10.10.10.1 localLimit: 20971520 totalLimit: 20971520 clientQueueSize: 6
func NewProperties ¶
func NewProperties() *Properties
NewProperties create 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 specify a default directory to store temporary files. SystemDataDir string // DataDir specify 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 specify the full target path whose value is equal to the `Output`. RealTarget string // 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 specify 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 specify the alive duration for which // uploader keeps no accessing by any uploading requests. // After this period, the uploader will automically 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