Commits

Ryan Stecker  committed ca2e4e0

Spin off tasklet for encryption requests.

  • Participants
  • Parent commits 3802873

Comments (0)

Files changed (4)

File steam3/client.lua

 	
 	return setmetatable( cli, client )
 	
-	
 end
 
 

File steam3/connection.lua

 	local emsg = struct.unpack( "I", packet )
 	-- todo: strip protobuf flag
 	
+	if ( emsg == EMsg.ChannelEncryptRequest ) then
+		tasklet.spawn( connection.handle_encrypt_request, "encryptionrequest", self, packet )
+	end
+	
 	self.client:handle_message( emsg, packet )
 	
 end
 
+function connection:handle_encrypt_request( packet )
+	
+	local msg = Message( MsgHdr, ChannelEncryptRequest )
+	msg:deserialize( packet )
+	
+	print( "got encryption request for universe ", msg.body.universe, "protocol version", msg.body.protocol_version )
+	
+	tasklet.kill( "finished" ) -- all done
+	
+end
+
 function connection.new( host, port )
 
 	local conn =
 	
 	conn = setmetatable( conn, connection )
 	
-	tasklet.spawn( connection.receive_data, conn )
+	tasklet.spawn( connection.receive_data, "tcpconnection", conn )
 	
 	return conn
 	

File steam3/msgbase.lua

 
 
+EMsg =
+{
+	ChannelEncryptRequest = 1303,
+	ChannelEncryptResponse = 1304,
+	ChannelEncryptResult = 1305,
+}
+
+EUniverse =
+{
+	Invalid = 0,
+}
+
 MsgHdr = {}
 MsgHdr.__index = MsgHdr
 
 -- todo: work out the nightmare of 64bit ints in lua
 
 function MsgHdr:deserialize( data )
-	self.emsg, self.target_jobid, self.source_jobid = struct.unpack( "Ic8c8", data )
+	local len
+	self.emsg, self.target_jobid, self.source_jobid, len = struct.unpack( "Ic8c8", data )
+	return len
 end
 
 function MsgHdr:serialize()
 end
 
 setmetatable( MsgHdr, { __call = function( self, ... ) return MsgHdr.new( ... ) end } )
+
+
+ChannelEncryptRequest = {}
+ChannelEncryptRequest.__index = ChannelEncryptRequest
+
+function ChannelEncryptRequest:deserialize( data, pos )
+	self.protocol_version, self.universe = struct.unpack( "II", data, pos )
+end
+
+function ChannelEncryptRequest.new()
+
+	local msg = {}
+	
+	msg.protocol_version = 1
+	msg.universe = EUniverse.Invalid
+
+	return setmetatable( msg, ChannelEncryptRequest )
+	
+end
+
+setmetatable( ChannelEncryptRequest, { __call = function( self, ... ) return ChannelEncryptRequest.new( ... ) end } )
+
+
+Message = {}
+Message.__index = Message
+
+function Message:deserialize( data )
+	local pos = self.header:deserialize( data )
+	self.body:deserialize( data, pos )
+end
+
+function Message.new( header, body )
+
+	local msg = {}
+	
+	msg.header = header()
+	msg.body = body()
+	msg.payload = ""
+	
+	return setmetatable( msg, Message )
+	
+end
+
+setmetatable( Message, { __call = function( self, ... ) return Message.new( ... ) end } )

File util/tasklet.lua

 	tasks = {}
 }
 
-function tasklet.spawn( func, ... )
+function tasklet.spawn( func, name, ... )
 
 	local task =
 	{
+		name = name,
 		co = coroutine.create( func ),
 		args = { ... },
 	}
 			
 			-- error when executing tasklet
 			if ( not didResume ) then
-				print( "unable to resume tasklet", res )
+				print( "unable to resume tasklet", name, res )
 				tasklet.tasks[ k ] = nil
 			end
 			
 			-- tasklet requesting termination
 			if ( res and type( res ) == "table" ) then
 				if ( res.kill ) then
-					print( "tasklet requested termination", res.reason )
+					print( "tasklet", task.name, "requested termination", res.reason )
 					tasklet.tasks[ k ] = nil
 				end
 			end