@@ -67,7 +67,7 @@ func NewManager(cfg *config.Config) (*Manager, error) {
6767 }, nil
6868}
6969
70- // InitProgress init the correlation information between peers and pieces, etc.
70+ // InitProgress inits the correlation information between peers and pieces, etc.
7171func (pm * Manager ) InitProgress (ctx context.Context , taskID , peerID , clientID string ) (err error ) {
7272 // validate the param
7373 if cutil .IsEmptyStr (taskID ) {
@@ -100,7 +100,7 @@ func (pm *Manager) InitProgress(ctx context.Context, taskID, peerID, clientID st
100100 return pm .peerProgress .add (peerID , newPeerState ())
101101}
102102
103- // UpdateProgress update the correlation information between peers and pieces.
103+ // UpdateProgress updates the correlation information between peers and pieces.
104104// NOTE: What if the update failed?
105105func (pm * Manager ) UpdateProgress (ctx context.Context , taskID , srcCID , srcPID , dstPID string , pieceNum , pieceStatus int ) error {
106106 if cutil .IsEmptyStr (taskID ) {
@@ -152,7 +152,28 @@ func (pm *Manager) UpdateProgress(ctx context.Context, taskID, srcCID, srcPID, d
152152 return nil
153153}
154154
155- // GetPieceProgressByCID get all pieces with specified clientID.
155+ // UpdateClientProgress updates the clientProgress and superProgress.
156+ func (pm * Manager ) UpdateClientProgress (ctx context.Context , taskID , srcCID , dstPID string , pieceNum , pieceStatus int ) error {
157+ if cutil .IsEmptyStr (taskID ) {
158+ return errors .Wrap (errorType .ErrEmptyValue , "taskID" )
159+ }
160+ if cutil .IsEmptyStr (srcCID ) {
161+ return errors .Wrapf (errorType .ErrEmptyValue , "srcCID for taskID:%s" , taskID )
162+ }
163+
164+ result , err := pm .updateClientProgress (taskID , srcCID , dstPID , pieceNum , pieceStatus )
165+ if err != nil {
166+ logrus .Errorf ("failed to update ClientProgress taskID(%s) srcCID(%s) dstPID(%s) pieceNum(%d) pieceStatus(%d): %v" ,
167+ taskID , srcCID , dstPID , pieceNum , pieceStatus , err )
168+ return err
169+ }
170+ logrus .Debugf ("success to update ClientProgress taskID(%s) srcCID(%s) dstPID(%s) pieceNum(%d) pieceStatus(%d) with result: %t" ,
171+ taskID , srcCID , dstPID , pieceNum , pieceStatus , result )
172+
173+ return nil
174+ }
175+
176+ // GetPieceProgressByCID gets all pieces with specified clientID.
156177//
157178// And the pieceStatus should be one of the `PieceRunning`,`PieceSuccess` and `PieceAvailable`.
158179// If not, the `PieceAvailable` will be as the default value.
@@ -185,7 +206,7 @@ func (pm *Manager) GetPieceProgressByCID(ctx context.Context, taskID, clientID,
185206 return getAvailablePieces (clientBitset , cdnBitset , runningPieces )
186207}
187208
188- // DeletePieceProgressByCID delete the pieces progress with specified clientID.
209+ // DeletePieceProgressByCID deletes the pieces progress with specified clientID.
189210func (pm * Manager ) DeletePieceProgressByCID (ctx context.Context , taskID , clientID string ) (err error ) {
190211 if pm .cfg .IsSuperCID (clientID ) {
191212 return pm .superProgress .remove (taskID )
@@ -250,12 +271,12 @@ func (pm *Manager) DeletePeerStateByPeerID(ctx context.Context, peerID string) e
250271 return pm .peerProgress .remove (peerID )
251272}
252273
253- // GetPeersByTaskID get all peers info with specified taskID.
274+ // GetPeersByTaskID gets all peers info with specified taskID.
254275func (pm * Manager ) GetPeersByTaskID (ctx context.Context , taskID string ) (peersInfo []* types.PeerInfo , err error ) {
255276 return nil , nil
256277}
257278
258- // GetBlackInfoByPeerID get black info with specified peerID.
279+ // GetBlackInfoByPeerID gets black info with specified peerID.
259280func (pm * Manager ) GetBlackInfoByPeerID (ctx context.Context , peerID string ) (dstPIDMap * cutil.SyncMap , err error ) {
260281 return pm .clientBlackInfo .GetAsMap (peerID )
261282}
0 commit comments