private void RenewStorageSession(Task task, long sessionId, int budget) { PeerSession existingSession = sessionsList.GetById(sessionId); if (existingSession != null) { PeerNode n = NodesList[existingSession.ToNodeId]; existingSession.RenewBudget(budget); if ((n.StorageSize - n.StorageUsed - n.ReservedSpace) > task.BackupSet.MaxChunkSize * budget) { CreateStorageSession(existingSession, task, false); } else { throw new Exception("Cannot Renew session #" + sessionId); } } }
private void CreateStorageSessions(PeerNode askingNode, List <PeerNode> targetNodes, Task currentTask, int budget, DataProcessingFlags flags, bool isIndexStorage) { foreach (PeerNode chunkDestNode in targetNodes) { PeerSession targetSess = null; try{ int sessId = sessionsList.Count + 1; targetSess = new PeerSession { FromNode = askingNode, ToNode = chunkDestNode, Id = sessId, //sessionId, Flags = flags, //currentTask.BackupSet.DataFlags, TaskId = currentTask.Id, Kind = SessionType.Backup, Secret = currentTask.EncryptionKey }; targetSess.RenewBudget(budget); CreateStorageSession(targetSess, currentTask, isIndexStorage); //if (SessionChanged != null && existingSession == null) SessionChanged(true, SessionType.Backup, targetSess.Id, this, chunkDestNode, currentTask.Id, budget); // 3 - we add the storage node(s) to task currentTask.AddStorageNode(chunkDestNode); } catch (IOException ioe) { // change back destination's available space //chunkDestNode.Available = chunkDestNode.Available + currentTask.BackupSet.MaxChunkSize*budget; Utilities.Logger.Append("HUBRN", Severity.ERROR, "dest " + chunkDestNode.Name + " not available (" + ioe.Message + "), looking for an alternate one"); // try another node, recursive call //ChooseStorage(askingNode.Id, s, 1, false, true); ChooseStorage(askingNode.Id, new PeerSession { TaskId = currentTask.Id, Id = -1 }, 1, false, true); } catch (Exception ex) { Utilities.Logger.Append("HUBRN", Severity.ERROR, "dest " + chunkDestNode.Name + " : " + ex.Message); } } }