Example #1
0
        public static async Task Publish(Packet pack)
        {
            var ap = new TcpCPublish(pack);

            byte[] reply = new byte[0];
            try
            {
                using (SHA1 sha1 = SHA1.Create())
                {
                    byte[] apByt   = Encoding.UTF8.GetBytes(ap.Description);
                    byte[] appId   = sha1.ComputeHash(apByt).Take(10).ToArray();
                    byte[] instByt = Encoding.UTF8.GetBytes(pack.Connection.Socket.RemoteEndPoint + "-" + ap);
                    byte[] instId  = sha1.ComputeHash(instByt).Take(10).ToArray();
                    var    pa      = new AppManager.PublishedApp()
                    {
                        AppId       = appId,
                        Connection  = pack.Connection,
                        InstanceId  = instId,
                        Description = ap.Description
                    };
                    AppManager.PublishedApps.Add(pa);
                    TcpManager.AppsByConnection[pack.Connection.Socket].Add(pa);
                    reply = new TcpSPublishReply(true, appId, instId, pack.Nonce).Build();
                }
            }
            catch (Exception e)
            {
                Log.Error(e, "Error while publishing an app");
                reply = new TcpSPublishReply(false, new byte[10], new byte[10], pack.Nonce).Build();
            }
            await pack.Connection.Stream.WriteAsync(reply);
        }
Example #2
0
 public AppConnection(TcpConnection connection, AppManager.PublishedApp app)
 {
     Connection = connection;
     App        = app;
     using (SHA1 sha1 = SHA1.Create())
     {
         SocketId = sha1.ComputeHash(Encoding.UTF8.GetBytes(DateTime.Now + "-" +
                                                            connection.Socket.RemoteEndPoint + "-" +
                                                            app.Description)).Take(10).ToArray();
     }
     Connections.Add(IdToString(SocketId), this);
 }