public void DownloadLink(string text) { FileLink link = FileLink.Decode(text, Core); SharedFile file = new SharedFile(Core.Network.Local.ClientID); file.Name = link.FileName; if (!Utilities.MemCompare(link.PublicOpID, Core.User.Settings.PublicOpID)) { throw new Exception("File Link is not for this Op"); } file.Size = link.Size; file.Hash = link.Hash; file.FileKey = link.Key; file.FileID = OpTransfer.GetFileID(ServiceID, file.Hash, file.Size); if (link.Sources != null) { for (int i = 0; i < link.Sources.Length; i += 10) { file.Sources.Add(DhtClient.FromBytes(link.Sources, i)); } } DownloadFile(file); }
public string GetFileLink(ulong user, SharedFile file) { byte[] sources = null; // if local shared file, get the sources we know of if (user == Core.UserID && file.ClientID == Core.Network.Local.ClientID) { foreach (DhtClient client in file.Sources) { sources = (sources == null) ? client.ToBytes() : Utilities.CombineArrays(sources, client.ToBytes()); } } // else getting link from remote share, so add it's address as a location else { sources = new DhtClient(user, file.ClientID).ToBytes(); } FileLink link = new FileLink() { OpName = Core.User.Settings.Operation, FileName = file.Name, PublicOpID = Core.User.Settings.PublicOpID, Size = file.Size, Hash = file.Hash, Key = file.FileKey, Sources = sources }; return(link.Encode(Core)); }
public static FileLink Decode(string text, OpCore core) { FileLink link = new FileLink(); if (!text.StartsWith("deops://")) { throw new Exception("Invalid Link"); } string[] parts = text.Substring(8).Split('/'); if (parts.Length < 5) { throw new Exception("Invalid Link"); } if (parts[1] != "file") { throw new Exception("Invalid Link"); } link.FileName = HttpUtility.UrlDecode(parts[2]); byte[] endtag = Utilities.FromBase64String(parts[4]); if (endtag.Length < (8 + 8 + 20 + 32)) { throw new Exception("Invalid Link"); } link.PublicOpID = Utilities.ExtractBytes(endtag, 0, 8); byte[] cryptTag = Utilities.ExtractBytes(endtag, 8, endtag.Length - 8); if (core != null) { cryptTag = Utilities.DecryptBytes(cryptTag, cryptTag.Length, core.Network.OpCrypt.Key); link.Size = BitConverter.ToInt64(Utilities.ExtractBytes(cryptTag, 0, 8), 0); link.Hash = Utilities.ExtractBytes(cryptTag, 8, 20); link.Key = Utilities.ExtractBytes(cryptTag, 8 + 20, 32); if (parts.Length >= 6) { link.Sources = Utilities.FromBase64String(parts[5]); if (link.Sources != null) { link.Sources = Utilities.DecryptBytes(link.Sources, link.Sources.Length, core.Network.OpCrypt.Key); } } } return(link); }
public static FileLink Decode(string text, OpCore core) { FileLink link = new FileLink(); if (!text.StartsWith("deops://")) throw new Exception("Invalid Link"); string[] parts = text.Substring(8).Split('/'); if (parts.Length < 5) throw new Exception("Invalid Link"); if (parts[1] != "file") throw new Exception("Invalid Link"); link.FileName = HttpUtility.UrlDecode(parts[2]); byte[] endtag = Utilities.FromBase64String(parts[4]); if (endtag.Length < (8 + 8 + 20 + 32)) throw new Exception("Invalid Link"); link.PublicOpID = Utilities.ExtractBytes(endtag, 0, 8); byte[] cryptTag = Utilities.ExtractBytes(endtag, 8, endtag.Length - 8); if (core != null) { cryptTag = Utilities.DecryptBytes(cryptTag, cryptTag.Length, core.Network.OpCrypt.Key); link.Size = BitConverter.ToInt64(Utilities.ExtractBytes(cryptTag, 0, 8), 0); link.Hash = Utilities.ExtractBytes(cryptTag, 8, 20); link.Key = Utilities.ExtractBytes(cryptTag, 8 + 20, 32); if (parts.Length >= 6) { link.Sources = Utilities.FromBase64String(parts[5]); if (link.Sources != null) link.Sources = Utilities.DecryptBytes(link.Sources, link.Sources.Length, core.Network.OpCrypt.Key); } } return link; }
public string GetFileLink(ulong user, SharedFile file) { byte[] sources = null; // if local shared file, get the sources we know of if (user == Core.UserID && file.ClientID == Core.Network.Local.ClientID) { foreach (DhtClient client in file.Sources) sources = (sources == null) ? client.ToBytes() : Utilities.CombineArrays(sources, client.ToBytes()); } // else getting link from remote share, so add it's address as a location else sources = new DhtClient(user, file.ClientID).ToBytes(); FileLink link = new FileLink() { OpName = Core.User.Settings.Operation, FileName = file.Name, PublicOpID = Core.User.Settings.PublicOpID, Size = file.Size, Hash = file.Hash, Key = file.FileKey, Sources = sources }; return link.Encode(Core); }