protected void SendSyncRequest() { syncState.random = random.Next() & 0xFFFF; var msg = new SyncRequestMessage { RandomRequest = (uint)syncState.random, }; SendMessage(msg); }
public async Task <SyncReponseMessage> SyncRequest(SyncRequestMessage request) { var handle = GetUserHandle(); var syncId = string.Empty; var followers = await FollowerStore.GetFollowers(handle); var following = await FollowerStore.GetFollowing(handle); var friends = followers.Intersect(following).ToList(); if (friends.Count > 0) { // Create a group for this sync syncId = Guid.NewGuid().ToString("N"); await Groups.Add(Context.ConnectionId, syncId); // Find users that follow each other // TODO: maybe cap/randomize the nodes foreach (var userTarget in friends) { // send them sync info from this user await Clients.User(userTarget).OnSyncRequest(new OnSyncRequestMessage { UserId = handle, SyncId = syncId, MaxCount = request.MaxCount, CacheTime = request.CacheTime }); } } return(new SyncReponseMessage { SyncId = syncId, Candidates = friends }); }