diff --git a/lib/src/download_engine/http_download_engine.dart b/lib/src/download_engine/http_download_engine.dart index 29c6f71..e696dce 100644 --- a/lib/src/download_engine/http_download_engine.dart +++ b/lib/src/download_engine/http_download_engine.dart @@ -665,11 +665,11 @@ class HttpDownloadEngine { ); return; } - nodes.sort((a, b) => a.lastUpdateMillis.compareTo(b.lastUpdateMillis)); + nodes.sort((a, b) => a.segment.length.compareTo(b.segment.length)); final targetNode = nodes .where((node) => node.segment != connectionChannel.segment) .toList() - .lastOrNull; + .firstOrNull; if (targetNode == null) { logger?.error( "_sendRefreshSegmentCommand_ReuseConnection:: Fatal! Target node is null!", diff --git a/lib/src/download_engine/segment/segment.dart b/lib/src/download_engine/segment/segment.dart index c75371b..09a281f 100644 --- a/lib/src/download_engine/segment/segment.dart +++ b/lib/src/download_engine/segment/segment.dart @@ -4,7 +4,7 @@ class Segment { Segment(this.startByte, this.endByte); - get length => this.endByte - this.startByte + 1; + int get length => endByte - startByte + 1; @override String toString() { @@ -12,22 +12,22 @@ class Segment { } bool isInRangeOfOther(Segment other) { - return this.startByte >= other.startByte && this.endByte <= other.endByte; + return startByte >= other.startByte && endByte <= other.endByte; } bool overlapsWithOther(Segment other) { - return this.startByte <= other.startByte && this.endByte >= other.startByte; + return startByte <= other.startByte && endByte >= other.startByte; } bool get isValid => - this.startByte != this.endByte && - this.startByte < this.endByte && - this.startByte + 1 < this.endByte; + startByte != endByte && + startByte < endByte && + startByte + 1 < endByte; @override bool operator ==(Object other) { return (other is Segment) && - other.startByte == this.startByte && - other.endByte == this.endByte; + other.startByte == startByte && + other.endByte == endByte; } }