I rewrote My Go App in Rust

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
are we live are we live so we're we're live uh okay I I can see in the chat that we're live but not uh not on Twitch a reactive app am I right right so that's why you have to write in react so your application is reactive enough hello everyone and welcome to yet another Recreation programming session with Mr zo uh let's make a little bit of announcement and officially start the stream officially start the stream uh so we're going to do red circle uh live on Twitch and what are we doing on Twitch at tevision website today uh today we are rewriting my Go app in Russ I'm going to give the link to where we doing all that twitch.tv/ and I'm going to Ping everyone who's interested in being pinged and there we go this stream has officially studed so uh yeah essentially I just remembered somebody reminded me when I uploaded the VOD of the previous stream to to YouTube somebody in the comment section reminded me uh that weren't you supposed aren't aren't I supposed to um like not start any new go projects because of the whole Telemetry stuff like that and I just realized that I completely forgot about that I completely forgot about the Telemetry thing and I suppose that was the plan of Google that was the plan of Google so to basically make it opt in make people get comfortable completely forget about it and one day one night turn on the Telemetry on for everyone so I I can see that I can see their plans I can see their plans so uh because of that we're rewriting the entire thing in Rust right so I mean uh to be fair I don't really care that much right I don't really care that much uh so if it wasn't super easy to do that I wouldn't even probably try to do that but uh I looked into what kind of things are available in Rust standard Library the crates that come with uh you know out of the box without installing anything and I I noce very cool things actually so let's actually do Rust up dock uh and see what kind of Primitives are available to us uh so yeah let's wait a little bit let's wait a little bit I think you have to do that without the ENT so RAB doesn't really work uh well with uh with emx for some reason sometimes so it's it's a bit weird uh it's a bit weird in fact so essentially uh one of the things we need one of the things we need we need TCP connection uh like very easy one uh out of the box we have things like TCP listener right so you can literally just create a TCP listener uh just like you would in in go and it's super easy to accept the incoming connections like this is literally the loop to to accept incoming connections and uh so instead of go routines we could just use uh regular threats right so we could use threat spawn uh right so you can literally just take a function and spawn it as a separate threat and this is something that we do in go as well and another thing that we rely on in the go Application is channels and apparently Russ does in fact have something similar to channels right so uh there is a a whole package called mpsc Channel npsc stands for multi producer single consumer fee for Q communication PR and this is exactly the pattern that we use in our application as of right now it may change in the future but that's the pattern that we use right now so what that means is that using only the standard library of rust we can translate go Application into rust almost one to one almost one to one because like rust for that specific case has pretty much the same parameters that we already use in go and I got really curious like what what's going to happen can we easily do that can we just like translate it one to one and see like the difference uh and and stuff like that that's kind of interesting right and again uh it's it's kind of annoying all the Google drama and them pushing to collect more and more data about the users is in fact annoying and I kind of want to push against that but if it wasn't this kind of situation where like rust already has all like the same Primitives and we can just like translate one to one I wouldn't probably bother right I wouldn't probably bother but since we have these kind of situations I thought that's a pretty interesting topic to explore don't you get thing right so just take this application that we developed and it's a pretty small application right it's 158 lines of code 158 lines of code and just try to translate it to rust preserving the same architecture preserving the same architecture I think it's kind of interesting I think it's kind of interesting I don't know where it's go but yeah something to explore remember to use rust stop update exactly so let me actually quickly do that I think I didn't do that for for quite some time so why is Ted that big of a deal is there no option to opt out already we already discussed that on Discord a little bit uh the Telemetry itself that specific executive decision that Google made is irrelevant to the whole situation it is IR relevant what's relevant is the bigger picture is basically the direction in which Google keep pushing the goal posts you know what I'm talking about so they're slowly they're pushing like slowly to that direction they're preparing they they tried they tried the waters they tried to enable it and the there was a huge backlash they still added the Telemetry but they made it opt in they're going to wait a little bit until everything settles out and they will try again if there will be another backlash okay they'll wait a couple of years they will try again until people will accept it and then they will say okay we're only collecting like how many times you build okay they will wait a couple of years and then say oh we're also going to collect how what what kind of dependency do you use it is also important for us right everyone's going to accept that okay so another goal post is actually knocked off and then they're going to say oh we also want to know your like email associated with your GitHub you don't mind that right so we we can associate you okay so we're going to like that and another goal post and another goal post and another goal post and on each goal post everyone is going to be saying that everyone is going to be saying that why is that that big of a deal it's just an email right so why is that big of a deal it's just the dependencies it's fine it's fine it's fine it's fine and it's just like the all these tentacles like slowly slowly slowly getting into that that specific technical decision it's irrelevant it is irrelevant what's what's relevant is the bigger picture you know what I'm talking about and of course I don't mind them collecting the amount of builds I do of course and that's the point you're not supposed to mind that that's the goal that's how it works uh right I really like this one just a second I just hope they don't reach the collecting how many times we builds fail that's the worst one that's the wor they should know that that's the huge humiliation for everyone um all right so we have updated uh so and let's just go ahead and uh you know create a hello world how about that uh so hello world hello world and I'm going to do Rust see so I'm not going to be using carer right because I don't really plan to use any third party dependencies right so I didn't plan to use any third party dependency so let's actually doain and go we have in fact hello world uh I actually kind of lost it there we go so look at that beautiful beautiful hello world and it's actually smaller than in go rust is more concise than go because in go what would you have to do you would have to do a package main package main Usef Mt and some other so here is just main print land hello world it's done that easy it's that easy anyways so uh let's actually uh take a look at TCP listener uh listener so TCP listener should be pretty easy to pull off I'm going to do STD uh use STD net TCP listener listener so and yeah so it's capitalized like that I can do TCP listener and it can just bind to 127 uh 0 01 69 69 right so this is what we're binding to if we take a look at the definition of the bind it returns result tocp listener right so this entire thing May Fail the way I like the way I like to uh handle errors in go right the way I like to handle errors and go is actually map error and log them right just log them but then since I'm mapping the error I'm mapping the error to unit right so is this value in go called Unit or is it is it called something else because in functional programming languages this kind of thing is called Unit maybe rust is actually calling it something else I don't really know does anybody know do we have any professional rust developers in the Stream it is also called Unit in R right so also called Unit and okay very well then it makes sense right so it's it's coming from function languages right uh so now uh let's actually go ahead and uh say something like error could not uh bind and let's say address right and here's the cool thing we can factor out uh this entire thing like that and that is going to work so there is a little bit of a string interpolation there's a little bit of a string interpolation in specifically this print L macros right so we can use that a little bit we can use that a little bit and that is basically it so uh there could be a little bit of problem with logging sensitive information and in Rust it could be a bit of a pain in the ass but that's totally fine right so this entire thing now returns not just result some sort of error uh TCP listener right so we sort of cons assume the error and we log the error now it returns this right and the reason why I like to do it like that is because you don't have to think about adapting the errors between like function calls and stuff like that and using boxes and interfaces and and stuff like that and quite often in majority of the situation you you want to just lock the error in the place that it happened and the only thing you want to propagate upwards right up upward the call stack is is the fact of an error happening right so usually error happens deep down in a call stack and you usually know what to do with that error there but up there you don't really care that much of about the details of the error down there except that the error has happened so you just use the fact that that error has happened to retry something or try something else you usually don't care about the specifics there so and if you start caring about the specifics it's usually don't have to be propagated too much upwards just like a little bit and it's super easy to to add in the majority of situations when the error has happened you just want to log it and just propagate an error uh the effect of an error app and continue and it kind of makes everything easier uh does anybody know what I'm talking about right so usually you want to propagate uh as much of the information about eror uh upwards as possible if you are writing um a library and you don't really know all of the possible use cases of that library in that case you kind of propagate as much of the information as possible and expose that information uh to the interface but if you're not developing a generic Library you usually kind of know what kind of information you need where and handle where so it's not really that important right so the complication of handling error errors comes from the uncertainty right when you're writing something very specific there is very little uncertainty so you can just hardcode things uh hopefully that makes sense at least this is my experience this is what I experienced over the years maybe it's not applicable to everybody but I mean this is quite often what happens uh at least to me anyways so and uh now it's just the result and uh interestingly now I can just always return uh result nothing and uh that's basically it and I can just like do dollar oh not dollar question mark Jesus Christ and uh that's basically it right so this is a listener this is a listener and we got the listener so we just got the listener if we couldn't do that uh we just print it and we just go up and it feels like a c code and it even feels like a go code isn't it right so because in go code what we did we just opened the listener it failed we checked that it failed and we log that and it's basically like that except we managed to merge these two lines these two statements right so in Rust we literally manag to merge these two statements because now we have assignment and simultaneously handling a log in that thing uh right so you can ignore the error in go though you can ignore it in Rust as well there you go you just ignored it or like you you can do something like that and you continue the execution you don't want to ignore it you just do that it's just like one symbol you decide you want to ignore it or you don't want to ignore it so Isn't that cool right uh so listener anyways so it's a little bit more like a verbos syntax right additional things you need to understand how the question mark works right so question mark is not particularly intuitive uh so there's like the syntax in in Rust is a little bit more noisy right so it's a little bit more overloaded in go it's pretty straightforward like there's not that much things going on uh right it's more a simplistic language okay so we can try to build this entire thing and go to to the compilation I'm pretty sure there are some compilation errors yeah because uh we need to probably do something like result result maybe I'm going to even just like do it like that and I going to have my custom result uh right which is just result that doesn't have any error but has the type T so that makes it a little bit easier uh to work with so and in here of course uh you need to return nothing uh there we go so and that compiled right it complains that listener is not used but that's totally fine uh that is totally fine there we go uh so now uh what are we what do we want to do we want to start accepting the incoming con connection so incoming returns you an iterator so it's some sort of a structure and it implements an iterator and what's the item of an iterator the item of an iterator is a result TCP stream error right okay so we have a sequences of results you have a sequences of results you either have the TCP stream or an error um right so the error actually oh okay so the error is the second one yeah that's that's what I want actually in this case anyway so we're going to do listener incoming right and here we get the stream and the stream can be like either failed or not failed right so we can do match uh Stream So you either get another stream and in that case you want to handle that thing and in case of an error you probably want to just log it but you probably don't want to you know exit right you want to continue just accepting things probably I don't really know we can do print L error could not accept uh connection uh connection and we can just Supply an error in here uh and just continue handling them I'm not sure if that's good of an idea but we're going to try that nonetheless uh okay and that should be fine that should compile as well and that in fact compiles so and in here uh what we can do we can just print something into this Stream So essentially if I understand correctly it's a TCP stream all right it is in fact a TCP stream and within the TCP stream do we have something like right does it Implement a right oh okay it implements a right interface so that means I can literally do WR Ln St uh let's say hello my friend okay Crow so and I suppose since the stream leaves for the entirety of this scope on the next iteration is going to be automatically closed to be fair this thing is so simple we can probably do it like that uh right so we can just do it like that we go and uh this entire thing think can return an error so in that case maybe we can just ignore okay let let's try to compile it and see what's going to say so um cannot write into TCP stream ah because it doesn't know that it implements right interface we have to explicitly import this entire thing otherwise it doesn't know how to handle that okay so write Ln returns result so it wants to handle that thing so it wants to handle that thing does any does it have any suggestions on how to handle that better um so result error found that so maybe we could still rub those things in that and put semicolons in there so the results in both of these cases are units can we do something like that okay cannot borrow the stream as mutable right so you have to explicitly say that this thing is going to be mutable so that's fine so in result is unused and in this case what we can do uh I don't know we can just probably log and ignore that right so say something like uh e l e l error could not write message to user uh so this is going to be an error and just ignore this entire thing like so I know it seems to be working so that's the whole thing right uh that's the whole think uh so synchronous networking ew exactly exactly EG exactly mate uh egg exactly so uh what do we want to do we want to try to run this entire thing uh before we run it so maybe it makes sense to actually say something like uh in for listening to uh address like so right so I'm going to uh rerun it one more time and now I'm going to literally maybe go in there right so we'll just go quickly in there uh right and run this entire thing okay so now I can do tell net 27001 6969 and uh all right so this is not how you do that okay so hello my friend KY so so it is as easy in Rust as it is in go believe it or not like at least that specific part uh at least that specific part so um okay first try mother the flippas first try so when it comes to sort of like a safe mode right so when it comes to a safe mode how can we Implement that um so because it's kind of difficult like in um in r in go we could just have a single function called sensitive right so sensitive which accept a string and returns a string uh and this is because go is sort of like this very much Dynamic GC is language it's so easy to just allocate a string and just like pass it around it's just like very much it feels like script in language sometimes but uh so in this case uh we don't really operate on the level of strings we usually operate on the level of types that implement interface display the Implement interface display right so and essentially to do the same solution we will need to convert the displayable things into a string and only then do the dispatching whether we are in safe or unsafe mode and it's just like kind of a pain in the ass so the more like a russh solution the more ideom Matic solution how people like to to say right so the more red solution would be to probably have a special structure right so let's actually create something like sensitive and it's going to be like a wrapper around some sort of a type right so because of that we're going to supply that type as a parameter uh right so and here we're going to have like an inner type called T and this entire thing is going to own uh that thing right it is going to own that thing so and then we're just implementing display for sensitive t uh and uh we also have to put T in here and we also have to say that t itself has to be displayable I don't remember where we have to say that I think we have to say it in here somewhere yeah there we go right so essentially for sensitive to implement the display interface the inner type also has to be displayable the inner type also has to be displayable and we can have some sort of like Global constant like a safe mode Boolean true right and when we are implementing FN fmt I'm intentionally not filling up not writing code correctly because the compiler is going to tell me like a little bit later but anyway so and then here what we can easily do we can easily do if we are in a safe mode just uh do write Ln uh for and it usually accepts some sort of fmt in here but it doesn't matter uh reducted uh reducted reducted uh otherwise otherwise uh otherwise write a L that inner thing right inner thing and I suppose here you take the inner thing from the self something like that so in the way you use that sensitive you essentially rub it all right so you essentially rrap it you do sensitive error I guess that's how I see that that's how I see that so that way uh you can quite easily control what mod you're in whether it's like true or false but uh this is quite easy because it's a global compile time constant or something like that making it um more Dynamic more runtime is probably going to become a little bit more difficult uh but we'll see we can probably put it behind some sort of like a reference count or something like that there is some mechanism to have Global variables in Rust there are some mechanisms to do that uh right so maybe Atomic bull some people suggesting Atomic bull doesn't doesn't really matter that much anyways so let's actually go to the compilation errors and see what the do we have all right so uh what does it say uh must be string literal uh so the thing I want to do I want to compiler tell me like what's the what's the signature of the fmt uh right because I don't remember it yeah so we need to import STD fmt and the way I like to do that is essentially fmt fmt there we go so tell me what we're supposed to do in here so uh here is the methods that's the method that we're supposed to have that's the method we're supposed to have so it's supposed to be like a formatter it probably comes from here as well um right so we can also probably say something like this there's a lot of stuff the compiler says to us we don't really need so that and in here we can just do it like that so and this is the formatter so we should be able to just do it like that there we go so that's the proper implementation that's basically why uh I didn't like write it right away because I don't remember this off the top of my head uh right so like I let the compiler to tell me like what kind of things what kind of weird noisy things I have to put in here because I don't freaking know uh all right so result remove uh these generics so it doesn't need this kind of generics right is that what you're telling me uh remove this semicolon okay are you happy now uh okay so uh has no field error okay so that essentially means uh we could probably do something like new u in here right so then Implement sensitive t uh FN new right which accepts the uh the T right the inner thing T and returns self and it is as easy as inner self inner self are you happy now it is seems to be happy uh right and when we are in a safe mode we should be able to just do something like that and it's it failed it couldn't bind that specific thing because it's already bound uh right but in any case uh there we go so listening to that uh but this is because we only made sensitive the error right so what if we made the address also sensitive uh sensitive new address so and since this entire thing is generic since this entire thing is generic it's supposed to be it's supposed to work with any type that is sort of displayable right so and it didn't work for some reason like what the uh so if we are in a because did I something up chat how is that even possible how is that even possible because I recompile it listening and it's supposed to supposed to not not do that supposed to not do that so that's kind of weird uh because okay so here is oh I me okay so I'm actually doing the the wrong thing this is the error reporting right so this is the error reporting and then I can do sensitive new uh address there you go there we go as you can see now it is redacted and if I do something like that it is not redacted I don't particularly like this solution honestly I do not particularly like this solution I think in go it's a little bit easier to pull things like that off uh I think it's a little bit easier but it is what it is right so to make it more run time as already say we have to use some weird forbidden magic or maybe Supply this kind of information with the sensitive right so basically save Boolean and then you supply it in here and then you have some sort of yeah you have to propagate it a lot in a lot of things and it's not particularly convenient so so rust intentionally makes this kind of stuff inconvenient for you for the sake of safety for the sake of safety it makes it very much inconvenient for you um right so because we probably going to have like a global uh configuration right and for example in in go you already have this sort of like like a global configuration and having a global configuration in Rust is usually pain in as right so you either have to constantly forward it to each call or maybe have a global variable or something like that or whatever so but anyway so yesu yesu yesu so we have a sensitive thing now we have a sensitive thing so I suppose maybe here uh I'm going to just like keep errors as usual I didn't think they're too sensitive maybe so maybe address is fine but specifically in case of an error maybe error is in fact sensitive H so in here can I actually just do it like that because I remember that in go that in go yeah we just did did it like that and it automatically listened to all of the uh all of the possible addresses maybe that's what we can do uh fail to look up information uh name or host unknown right so you cannot do it like that in go you probably have to do it like like that and only then it will work okay so if you want to listen to All of the addresses in Rust you have to use 0000 0000 z um so that makes sense all right uh so people suggesting to use tupal stct for the uh for the sensitive it's not a bad idea let's actually quickly do that I think it will make it easier uh right because you don't like a little bit less Sy syntax right and we probably won't need this kind of thing uh right so so let's actually try to do it like that um so semicolon um so and because of that we probably want to do something like uh can I do self inner uh self like this and then I can just remove that and so when it comes to here it becomes easier that's for sure it actually becomes way easier okay so that's a good idea thank you thank you so much thank thank you so much who suggested to to use it like that and now it is basically equivalent to what we had in go isn't it uh it's basically equivalent because in in go we just had sensitive which is just a single function and you write just a parameter to this yeah it's basically equivalent syntactically equivalent to go not semantically not semantically but syntactically uh right so that's pretty cool I think right so because there's no actual like conversion between type and string and stuff like that we just directly uh forwarding this thing to uh to the formatter and stuff like that so people Al suggesting to maybe use something like fmt uh right as well also not a bad idea also not a bad idea so it's see a little bit better even uh ISU ISU ISU okay so let's continue so we sort of resolved the sensitive situation right so now we have everything we need the struct is not required could just uh make function to honestly no you you can't I don't see how you can do that honestly because with with at least without converting the type into string at least without the converted type into string I don't see how we can do that so and I feel like this is one of these things that people can caught up too much because it's such a simple problem so there's a lot of opinions and it's easy to have an opinion on how to do this kind of thing so I think I'm going to claim this to be the final solution of this specific thing and we're going to move on and we're not going to discuss that anymore because you can basically R hole on that thing for too long right without soling anything so I'm not discussing that anymore this is how it's going to be implemented all right so uh what else do we have um because it's too easy to have an opinion on very easy um so now the next thing we need to do we need to maybe start um having like separate clients that listens to things right so maybe in even in separate threats maybe even in separ separate threat so let's actually have a client and what that client is going to accept I suppose we can just literally move a TCP stream into that thing uh right so we're not going to handle it right so it's just going to be like this um and essentially uh we want to probably spawn a thread I don't remember in go go routines are they real threats or are they so-called green threats they green threats okay so it's not going to be then equivalent to go right so they are in fact green threats all right all right so but I mean I'm still going to using um going to be using real threats just to like map the code one to one um right so uh threat spawn right so let's do threat spawn uh and so let's see how it is Implement so it accepts a function and stuff stuff like that Returns the join handle though returns join handle we probably not going to join right so we're going to just continue and move on with these things threat spawn uh and this is going to be a function and within that function we can just do client um client stream right so that's that looks fine might as well actually move hello Min to here cu so and uh this entire thing might as well also return uh this thing well I mean this one is going to take care of this kind of thing um okay so can I even do something like this maybe even something like this well yeah probably have to put some in here for it to actually work properly okay so let me try to compile and see how uh well it's going to work or not so we don't have a TCP stream let's include a TCP stream it's going to go here uh go what else do we have in here so this is a stream it wants to be mutable sure uh now what do we have in here this thing doesn't have to be mutable but since we're moving it inside it's going to become mutable anyway uh right because the client now is the owner which is not particularly great idea I think uh which is not particularly great idea because it's probably going to be shared between uh the server threat as well right it's probably going to be shared between the server threat as well but who cares who cares all right so let's create a server thread right so this is the server thread and uh now let's just return resolve this kind of thing and what do we accept in a server thread we uh like at least in go server so we accept the basically Channel messages all right so the channels in Rust are a little bit different actually so they when you create a channel it creates actually two ends the sender and the receiver which is actually a little bit better I I like it better than in go because sometimes it's kind of difficult to keep track of who's the receiver and who's the sender but maybe in go it doesn't really matter maybe like there like um you know can work in both directions but in our case we use them as unidirectional things and it's just like easier to track this kind of stuff uh in mind opinion right so I think I think it is so let's go ahead and create a new channel so to create a new channel because what we're going to be storing in the channel what we're going to be storing in the channel we're going to be storing the uh the messages right so uh let's create maybe in Num uh is going to be message and what kind of messages we're going to be using in here so client connected so that's the first message then client disconnected and then uh new message so they also supposed to have types attached some data attached to them but we're not going to attach anything yet we're going to attach it later so and server is basically becomes a receiver right so we accepting messages messages that are uh receiver of messages there you go something like that so I'm going to put it like this so this is going to be to do so this is the receiver so we'll need to have all of these types so let's quickly do and let's include things like sender receiver uh receiver and so on and so forth let's go through completion erors just to see what's going to what's going on so this is uh expected found Channel really ah it's because it's like this so channel is a function not a package okay all right so it compiled surprisingly it compiled surprisingly all right right right um so now so here's the listener and stuff like that we want to create a channel uh right and a channel is going to consist of the message so the first one is the sender message sender message receiver receiver like this so and it does that without error so it creates that without any errors that's pretty cool so then we want to spawn the server thread we want to spawn the server thread uh like so thread spawn uh spawn uh server message receiver specifically right so this is the huge difference between like rust and go specifically because in go you just create one channel and you use one Handler for both receiving and sending in both of the threads right here you have to put different hander to different places right different Handler to different places um so and what's what if you're going to have like a several senders can you share the sender that's a very interesting question because we are effectively going to be sharing the cender between several places how do we effectively share the center so that's very interesting question so maybe we should read that so this creates new asynchronous Channel returning the sender receiver halves halves all data sent to Sender will become available to receiver in the same order as it was send no send will block uh the Callin threat uh this channel infinite buffer um this channel has infinite buffer unlike sync Channel which will block uh after the buffer limit is blah blah blah whatever so the center can be cloned to send to the same channel multiple times but only one receiver is supported this is perfect okay so essentially every time we create a new client threat we can just clone a sender and hand that Center to it okay that's that's pretty cool that works for me so again it's not going to be equivalent to go right because these are real threats which uh could be a little bit heavy for the system right so for the system like green threats are pretty cool that in that sense that they're very lightweight so you can create like a lot of them so I think in the case of rust we won't be able to create that many threats um as many as we could be able to do that and go uh but then then once we have a working solution in Rust maybe we can basically re architecture the whole thing to support more connections and stuff like that right so uh so yes so yes so that's actually pretty cool you can clone it so it it fits perfectly to our use case I really like that okay so the client here uh so this is the messages uh so this is a single stream and we're also accepting messages but this is a sender of the messages right so this is the sender of the messages and the client whatever the client sends will be received by the server in here right to reset by the server in here so now every time we create a new client what we're effectively doing right so we're just doing message sender and we just clone this entire thing right we just clone this entire thing hopefully that will work I don't really know so let's actually go to the compilation errors and see uh right so uh we don't really use this messages so this is a warning um so closure May out leave the current function but it borrows message center yikes so here is an interesting thing how can I look one way I can I can do that right so I can do message send sender uh like this and then I move the message sender uh like this can I uh all right so that it is so funny that this is the solution it is so funny right because I suppose um it moves these things inside of this function inside of the thread right and when when you try to do it like that it first moves message sender and then clones it so you need to kind of Clone it outside and only then move it uh like I mean it makes sense to me it makes sense to me it's just funny that that's how you have to do that it's kind of sad that like you really need to understand these kind of things um right you really need to understand this kind of things uh which is not particularly newbie friendly oh by the way when I released that whole sort of like a rant about like userfriendly equals professional h stle i I've heard one interesting point is that like rust is kind of an exception out of that right R is kind of an exception because it's newbie friendly right and professional and stuff like that not professional style like if you think that rust is newbie friendly rust is not newbie friendly like factually de Factor de Factor rust is not newbie friendly it is marketed as a such for some reason I have no idea why it is marketed as newbie friendly but it's note it is very much newbie hostile very much newbie hostile I'm telling you so so quite often it is marketed as newbie friendly it is really marketed as new friendly but it's actually not it is very much not [Music] um all right so to be comfortable with uh with the rest to be comfortable with the rest uh you either have to do it for like a very long time or you have to have background in pure C pure C pure c c Plus+ separately you need to have the ground in p c and C++ separately and Hill and all this three simultaneously if you have these three backgrounds simultaneously you would feel comfortable in R yes sure so or a camel maybe a camel also fine right so you can replace hker with the come but hasker would be a little bit better right so um [Music] I have theground in those three I still don't like right same I also have background in all of the three I also don't like rust but I was not saying that to feel comfortable right so it's it's a little bit different right you can comfortably program in this language without liking it but I mean it's it's very subtle thing uh anyway so uh let's continue so this entire thing compiles uh this entire thing seems to be compounding so that's pretty good that's pretty Gucci that's pretty Tama Gucci so how when do we send stuff to uh to this thing I suppose we're sending message client connected uh before yeah I didn't really know why the we do that in here uh personally today I would have actually moved that message send inside of the function client I think that would make sense to me right so just like move it there so but anyway we can do it in here then uh we can do it in here so we can take the messages and the question is how do you send it by the way I'm using this channel API for the first time in my entire life I literally learned that this thing exists before the stream and I started the stream right away so I'm literally figuring out how to use this thing right on this stream uh all right so Sandra let's take a look but we have documentation right so we have documentation so I'm pretty sure it should have method sent right so I mean that's pretty expected uh right and you just send the thing there okay so let's actually read what the this thing does attempts to send the value on this channel returning it back if it could not be sent um a successful send occurs when it's determined that the other end of the channel has no hung up already an un successful send would be one where the corresponding receiver has already been deallocated now that the return value error means that the data will never be received but the return value of okay does not mean that the data will be received is possible for the corresponding receiver to hang up immediately after the function returns it's to hang is a irregular verb right so hang Hung okay so I'm sorry English is hard for me I don't speak English uh this meod will never block the current threat and to be fair it doesn't really need to right so does really need to block anything okay uh so let's send uh something like message uh message client uh connected right so for now we're not going to attach any information so the message client connected so map error so if we couldn't do this kind of thing so that me that means that the receiver has been delocated and it makes sense to just like go out of here right so so e uh print Ln um so let's say could not could not send uh message to the server threat and this is basically an error and to be fair I'm not quite sure right so I'm not quite sure what if I really like that because I'll have to do that every time I try to send so maybe it would be nice to have some rapper but I mean who cares whatever how much money to get you to write this in brain Fu I probably won't write this in brain fog but I actually want to do a brain fog stream that would have been interesting I think like where I try to program uh some simple algorithms in brain now what do we need to do we need to start like reading things from the buffer so let's actually start in infinite Loop right so apparently in Rust there is a special construction to create an infinite Loop which is kind of cool not going to lie and uh so here uh we can take a look at TCP stream right so let's take a look at TCP stream does it have a read so there is a read timeout oh yeah by the way right so apparently the for at is vulnerable to slow loris but it's kind of interesting it's vulnerable not to the writing slow lores but to the reading one right to the reading one so essentially if we take a look at the go uh thingy and we take a look at the server uh server think uh so in a server within within a single threat what we're doing we're iterating through all of the clients and we're synchron ly writing things into each individual client so if there is a one slow reader among the clients it will sto the entire server I'm surprised nobody nobody tried that on the previous stream you could have actually sto the entire thing right so uh so we're going to actually translate it as it is so the rust version also will have that and once we finish translating we're going to fix it in the rust version right so that's basically the idea so but the keep in mind right so prepare your slow loris attackers right so to stall the entire server to stall the entire server so we set the message connected and now what we need to do we need to we can use the read timeout uh or maybe maybe not it doesn't matter so I want to just do a regular read uh and and read time out what does it return Returns the read time ah it doesn't okay I just had a huge brain for I for some reason I thought this is a method that performs the read with a certain time out and I'm just looking where is the output where is the buffer into which it's reading it just returns you the values set within the okay maybe it's not my problem because why didn't you call it get read time out or something like it looks like an action it looks like it looks like a perform read with a timeout and it's just like look where is the output H Jesus Christ anyway so it probably reads through the read interface yeah there you go so it has a read interface and blah blah blah so what kind of stuff does read interface have right it has a limited uh thingy it accepts the buffer that is mutable I hope that the fact that this buffer is mutable doesn't mean that it's going to resize it I'm having [Music] PTSD anyway so I'm just joking obviously so uh um okay good so as suppose uh we could basically allocate uh some sort of like a vector uh so if I take a look at the V can I allocate Vector with a certain size uh so I can do new it's just like a new thing new in uh right it's the vector will not allocate until elements are published okay so it's probably not what we want uh so there's a width capacity right so there is width capacity is there something else uh so it's probably not we could probably resize this enti thing yeah so that looks fine that looks fine so resize with and we can use that as a buffer can use that bu okay uh so we can just create a Al is going to back uh resize uh width so there's just resize but I suppose it um oh it's resized with a function so the value is computed with a certain function I don't think this is what we need we just need this thing um so resize so the size is going to be 64 and just fill it up with zeros right so this is going to be definitely like bytes um I'm not going to specify any of the types because I hope it's going to infert them somehow right it's going to infert them somehow so in here we have read and I'm going to be basically reading into the buffer right so this thing has to be mutable and there we go we just read into the buffer so and reading may also fail of course right so it may fail um um map error so this is an error and what do we want to do in case of an error right so if we take a look at how it is implemented in go right so how it is implement it and go in case of an error we just close the connection right so we just simply close the connection but suppose we don't really have to close it explicitly we can just exit this entire function so that's totally fine but one of the things we may want to do one of the things we may want to do we want to tell the server that we uh just disconnect us somehow just disconnect us so and we do that by doing uh message send right so we do messages uh we do messages and we just send uh disconnected right so client disconnected and we just exit afterwards uh and since I put this thing in here so it's totally fine okay that's cool uh so and this entire thing should return n and now we should be able to oh okay so it works this is actually works too well in my opinion all right that works too well surprisingly and of course this can fail as well so maybe we'll have to we'll have to do something about that we'll have to do something about that all right so uh people say tell me that slices are usually like this uh this is how I can take a take a slice and now I need to try to convert a sequence of bytes into utfa string so can I do something like from utf8 is there something like that so Str Str from utf8 okay so and it can fail which is good right so if we didn't manage to convert it properly we won't be able to do that what's interesting is that um we're going to be striking the people who didn't send utf8 compliance stuff we're going to be striking it and we can't really strike them on the client side we have to strike it on the server side so because of that I think I'm not going to be converting it to ETF here yet I'm going to be not going to be converting to ETF here yet uh so I think I'm going to be sending it to uh the server messages new message right so new message uh But Here Comes an interesting thing here comes an interesting thing um we'll have to copy this entire thing we have to copy this entire thing uh so and the messages the the buffer messages that we operating with in here are very small so maybe copying them is not that much of expensive maybe it's not that much expensive so maybe that's totally fine so right now I'm just outlining how it's going to go right because uh we're going to go we're going to have a separate session where we go through um compilation errors and stuff like that um compilation and stuff like that and uh so Funk client that is basically it isn't it yeah that's actually smaller than I expected like it's generally more concise it is generally more concise and in new message right so we won't be able to do something like this in here right because this thing has to be owned right this thing has to be owned uh but I don't really plan well I I can do something like that can do something like that so just like because when you have a own the slice it's basically a vector right so an owned like thing is basically a vector yeah we can put it in a box I guess we can put it in a box uh but I'm I'm not sure right so we can just do it like that we can just do it like that for now um all right so in a Go version we also were sending the sort of the connection itself right so the TCP string uh but I'm not sure if we'll be able to uh we can't really copy TCP string one of the ways we can do that is probably share it between this uh the the threats or something like that uh right so we'll see we'll see yes I'm actually an ironically expecting we'll get to this point at some point in hisory classic rest am I right so I mean this is like yeah this is an an ironic type this is an an ironic type that people use in Rust right so in each layer of this onion has a meaning each layer of this onion has a meaning um I suppose in this particular case it does doesn't make much sense right so it's just like a box itself is a pointer so you putting it behind a mutex like you could just use ARC without any box and I think you actually put Arc inside of the muto I think I don't quite remember I think uh so outer is mut inner Arc and then the value this is usually how you share things between the threats that needs to be sort of synchronized or something like that I don't quite remember there's Arc is outer oh okay ah I yeah yeah so you have a value behind the mutex and then you need to share the mutex between the things and that's why okay so we can I think there it even has examples I think it even has examples for for this kind of thing uh all right so yeah Arc is outer okay so that's true good yeah Arc is for multiple ownership yeah yeah that makes sense that make sense so I'm registering for 1 hour so let's actually go to the compilation eras and maybe make a small break afterwards uh right so what do we have in here so message local uh okay so this is a messages messages no method to read for a TCP stream and this is because we need to do this kind of thing but we're already like importing right right so we already import right so I can do read there we go [Music] so in here we can do two V EV EVC uh all right what else do we have in here so unused write which is reading okay so you you don't need that anymore uh so error and used error uh yeah so e print Ln uh ER could not read message from client uh error like this and then we just perform that like it already compiles why the does it compile already I'm I'm surprised so we have unused this thing and I suppose do do I really care if it fails or not like at this point at this point we kind of already failed completely so there's no point in even trying to handle this kind of thing all right we failed to read do we really care where this thing received that or not so even if it doesn't receive is there something we can do right so there's nothing much we can do so just like that's why I'm going to just ignore it uh and so here we do send and this is map error uh and if we couldn't send that means there is no Channel anymore so um could not send message to to here okay what what the do we have in here uh okay so because this is a map error all right that's too easy that is too easy all right so we went through the compilation errors as already said I wanted to make a small break because I ran out of T so I would like to replenish my T and after the break we going move towards the server so the the real shed will hit the fan when we'll have to do something like this we will need to have to do something like this we'll need to somehow tell uh the server threat who we are in go we used to do that by sending the PO to the connection right um in in here we could try to just make it arcti uh let's give it a try Okay so let's actually introdu this Arc and see if it's going to work that easily so this is a STD sync Arc uh all right so use STD uh sync Arc and Arc by the way for for those who doesn't know it's essentially shared pointer it's like shared PTR from C++ uh but with uh Atomic reference counting right so it's Atomic thread safe and stuff like that that's basically what it is um soting did you decorate your house with Halloween I do not celebrate Halloween I'm sorry and nobody among my neighbors celebrate Halloween and I never seen a single person in here who celebrates Halloween honestly so it's it's not the thing in in the place where I live I'm sorry um nether here in Eastern Europe yeah I'm basically I'm also basically living in Eastern Europe so my Europe is so Eastern it's Asia that's how how Eastern my Europe my favorite joke of all time I know I made it already twice um right above Mongol exactly we live near the border of Mongolia we don't have hallow here we [Music] have that's what we have instead hen um now yeah I want you to try to to do the arc thingy right so essentially we're going to do Arc TCP stream um okay so and in here right so we're probably going to pass this thing like that right so we're going to pass this thing like that uh this but has okay so I'm going to put it in here right I'm not sure if I yeah we're going to keep it like that why not so and when I'm doing it like this okay so this is cool uh how do I construct an arc right so this is this is similar situation right but instead of cloning the stream we're going to be doing Arc new stream like so uh is it going to help us variable doesn't need to be mutable sure sure enough um so can it borrow data in AR Arc as mutable okay so you can't borrow it as mutable um what do I have to do to make it mutable is there anything I have to do so that means I have to put it behind the mutex right do I really have to put it behind the mut if I want to make it mutable if I want to make it mutable looks like I have to put behind mutex looks like I have to put it behind the mutex though we can try to do something that we couldn't do like easily in goal right so we could have another sort of like a channel that through which we receive what we have to send so that means we'll have to put like okay so I feel like we will have to do the newex thing here okay so that means it's not as easy as they expected so we're going to do that after the break then right so let's first do the break and after that we we can continue um okay so here is the question I just realized that I probably need to do an unsolved computer science problem um right how can I share TCP stream between two threads and in one thread read and another thread write and both of these things are synchronously can is this difficult computer science problem solved in Rust is it possible to do in Rust looks okay people are uh guiding me in the right direction I think I'm not 100% sure but I think they're guiding me in the right direction so we're going to try to do TCP stream because the words like splits and locks kind of sound what I need but I know the chat they're going to jate me they're going to jate me so uh but it kind of sounds plausible chat is basically GPT chat GPT right so it just confabulate some you know plausible that doesn't actually isn't actually true but I mean it wastes your time anyway um so what do we have in here so try clone no delay linger blah blah blah uh so sfd so there's a from into rows and circuit nothing particularly interesting so there's a structures incoming well I mean it's an iterator that contains all of these things so people were saying word split okay so let's actually try to search for split so there's iio split uh so it's probably related to iio right so it's probably is anator over a content of instance read buffer split on particular nah that's not what we want that's not what we want so looks people were also saying looks so I know that locks are a thing for STD in STD out and so on and so forth but when I have like a TCP stream I'm not really sure how easily I can do this kind of stuff so and as you can see STD lock is is this kind of thing so I feel like I can't easily do that uh RW Lo so something like RW Lo could be a thing so this is for uh read writer look this this type of look allows a number of rers or most one writer at any point of time H um the right portion of the log typically allows modification so uh allows a number of readers or at most one writer at any point of time uhhuh so read and write are implemented for poter stream meaning that you only need a shared reference no need for mutex uh for mutable mutex uhhuh so does that mean I can just use but I mean I tried to put AR here D I uh so okay let's actually see so somebody suggested uh let me let me see so read oh okay so I lost this kind of thing [Music] freaking okay so finally so there is an annoying thing in chromium uh when you basically follow the link with an anchor but then you recite the browser even if you refresh the browser it doesn't actually align with an anchor and it's extremely annoying I think it's been in Chrome for for ages since I remember like it's it's a very much chromium bug or whatever and it's just like you have to open it in a new tab to actually reset it or something same so I'm not the only one who struggled with this kind of it's just so annoying I'm pretty sure it is a bug I'm like I'm pretty sure it is a bug uh fix it yeah so and like it's just like yeah was because quite often like I open it in a different window so it had a different size so I had to move it in a different monitor I'm sorry so it had a different size so then I moved it to a main Monitor and obviously it resized and now it just like doesn't recover uh and I can even check like in this here yeah it's it's it's just like the position of the anchor is actually lost X server moment I mean is that an X server or is that I I feel like it's a chromium BG not X server BG honestly um so we just need to have a shared reference we just need to have a shared reference but when I tried to do this thing when I triy to do this thing it didn't allow me to do that right so because Arc is a form of shared reference when I tried to put Arc we started to have a problem with the Reon here right we did in fact start having problems like with read here uh so D on the arc okay so that's a good thing okay so I suppose we're learning something new all right so let me take a look so what does drf even mean uh okay so it's probably method of something of some interface that Arc implements so it's a method of D so we have to explicitly D reference it's it's just a it's just a d but why do you have to well I mean ah and it returns you still returns you a reference okay o o okay so that's interesting so used for immutable D referencing operations like that in addition so it basically for things like arc on maybe a box and everything it will basically turn it into this like you know regular reference huh that's very interesting okay let's try it again let's try again uh use ARC in here everywhere right use ARC in here everywhere maybe it will do something so honestly maybe I want to make it like a mutable here anyway so we just go ahead and try let's just go ahead and try can borrow data as mutable DF uh right and what did happen in here so it has to be a method uh the r method not not found in so it didn't work uh the following trait is not ah okay okay okay okay I see I see what you've done in here um okay so value moved in here so that's fine that is fine uh right because ahuh so we kind of moved it so I suppose what I have to do in here I have to clone it one of the things you can do with arcs is you can clone them uh you can clone them so people say a ref works as well but we'll see so it's it's similar so let's just make it work at least okay thank you so much thank you so much who who helped me especially moad I know that other people also help but uh moad actually uh watching my streams for quite some time and their advises in the chat are super super useful quite quite a lot so I'm going to give them VIP so you're VIP now so I'm going to promote you to VIP because I see you in the chat all the time and you're actually contributing to the quation L so uh yes yes yes thank you so much it's actually really cool all right so that's that's kind of cool that it works uh right and people say you can do as ref as well so and that doesn't require d one less line who would have thought who would have thought um okay so that's pretty cool uh and since it's a reference we can hopefully it doesn't really move that much around we can probably use it as the key in some sort of a hash table well no we what we did in go we actually used the IP address in the hash table so yeah so that makes makes a little bit more sense uh okay so on the disconnect we also sent the author so we can do TCP stream like so uh so this is the Alor and we can just do it like that stream colog um all right I'm really surprised with that compound okay okay okay so that means we're done with the client threat basically basically done with the client threat so so let's go ahead and Port the um the server thread Funk server Funk server so what did we have in here so there we had a client uh client map so I suppose one of the things we probably want to have we want to have a structure client and a structure client is rather interesting right so let's actually have struct client and uh here we have a connection we can have a similar connection which is going to be Arc in TCP stream so I'm not going to do last message and strike count yet so let's just Port without rate limiting and uh Banning and out Banning and stuff like that because it's easier right so it's just easier to uh map the behavior um okay so and then we have clients so to have clients we'll need to have the hash table collections uh hash table like so like so aan server so let's introduce mutable clients uh hashmap and the question is what are we going to use uh as the key in there so we used in go the string that represents the remote address basically IP plus the remote Port IP plus the remote Port so if we take a look at TCP stream do we have a remote address in there uh we have um local address okay that's cool but it's a local address it's not really that interesting for us does it have a remote address it has a peer address okay that is cool so it has a peer address uh so it's either ipv4 or IPv6 that is cool so does it Implement ha hash does it implement it does implement hash so we can put this entire thing as an index in hash table that's pretty cool sounds good to me sounds Gucci sounds Tam Gucci you know the usual stuff so the only thing that bothers me a little bit why the fact that return result Returns the socket address of the remote Pier of the TCP uh connection so does it perform some sort of a system call every time you call this method does it not cach it or like I don't really understand why the does it need to return result because how can it fail excuse me um so let me let me see so it's a uh pure address how many implementation is there imple okay so the implementation internally this entire thing is a TCP listener yeah we have to go like very deep into this entire thing we have to go very deep into this entire thing but yeah whatever all right so let me let me start coding I suppose start coding uh the first thing we want to do we want to organize maybe a loop we want to organize the loop and as you can see in here we have uh an um an infinite Loop so we need to take the messages uh and we need to work with the receiver re receiver uhuh so here's the receiver and we receive things attempts to wait for Value uh on the receiver an air if the correspondent channel has hung up this uh function will always block the current threat if there is no data available and it's possible for more data to be sent once at least one sender still exist once a message is sent to the corresponding sender uh this will wake up and return that message okay so that's precisely what we want so messages uh receive and we got the message we just got the message uh so I'm not really sure how should I react to a receive error so when If the message is hung up so an error if the corresponding Channel has hung up what does it mean does it mean that it doesn't have well it's probably going to hung up if we lost all of the message senders but there will be always at least one message sender from which we're cloning things from which we're cloning so yeah that's actually pretty cool um so from which we cling so that means even if there's no clients it's never going never going to be hung up uh right so that means that's totally fine so we can do something like map error uh we can log the error uh so it should probably never happen right so it should probably never happen because of that we can just expect that it's going to be fine right so expect uh the channel the server uh receiver is not uh hung up right so this is what we're going to do here uh and uh we just take the message and we can have several situations in here so we have that so this is the author right so this is the author first alter then disconnected uh disconnected and then uh new message right new message there we go and this is basically the B of the message that we received okay so let's go ahead and compile and go to the compilation errors so unresolved import collections HH map okay uh all right message like this I mean technically like it's correct I suppose uh unreachable expression so all right let's remove that annotation needed for type annotation need for HH okay so it couldn't figure it out yet so because of that um I need to well I mean it's not going to be needed as soon as I try to push something in there so it's annoying right so I can just add it right away to make it compile but as soon as as I like Implement at least this thing it it's going to be fine all right so it's kind of forcing me to implement it right away which is annoying in my opinion but whatever um so here's the author uh we so this is already a connection so we have a pure address so this is a p address and we probably want to preach it somehow right so it doesn't like we don't call it very often but I guess that's fine uh so it's going to say expect to do um cache the pier address of the uh of the connection right so this is something we want to have in here so this is going to be an address like so and then we what we're doing in here we're just uh we're just adding this thing in there right so we're just adding a new client so clients insert and we can do a client like so this is the connection um so this is an address which we probably have to clone right so I'm pretty sure it is clonable so we're going to clone it and what we're doing we're taking the author and we cloning the author as well right so we're storing the copy of that Arc thingy in there and that's basically it so that will not require to provide any parameters in here anymore hopefully and compiled yeah so it kind of forces me to go implementation before I even comp manage to compile this entire thing because yeah cannot figure out the types it's kind of annoying it's kind of annoying but it's it's rust it's supposed to be annoying right so it's it's designed to annoy the out of you uh right so we have this but it's unused so that that's fine that is totally fine that is totally fine okay so when it comes to a client disconnection client disconnection what do we do we take the address yet again so Alor I might as well copy paste this entire thing might as well copy paste this entire thing uh so and what we have to do we have to just delete it from the map all right so we have to delete it from the map um uh if it doesn't exist I don't know uh we're just going to ignore that fact so hashmap so do you have delete or is it remove it is remove okay so that's fine uh and returns an option yeah we don't care if it exists or not we just remove it right so clients remove uh address so it has to be by a PO by a reference right so we have to do it like that so let's recompile this one more time and it seem to be working okay so we can quite easily just add and remove from the map and stuff like that so the next thing we have in here is uh send the message send the message so to send a message we'll have to be iterating the hashmap so hashmap I think it has something like items if I'm not mistaken right so well you can just do iter and it gives you gives you an iterator the the item of which the item of which is what a pair of key value we can do do something like that right for um client eer right for client eer and we can probably just take values something like values is even better hashmap values hashmap values right and it Returns the in iterator of only the values that's a little bit better so we can do values uh so this is the client client in clients that's pretty cool though okay we'll need a key anyway we'll need a key anyway uh right because it's going to be an address right it's going to be an address so and we'll have to do this thing as well but this is going to be author address right so and we need all of that because we're going to be distinguishing if address not equal author address only then we want to send that to that client and blah blah blah blah blah blah right so uh okay so maybe I'm going to actually follow the code in go right so as you can see in here we just take the client we take the connection and we're just writing that entire stuff in there right just writing uh writing those bytes right in there very dangerous thing right so we don't screen them we don't do anything with them we're just writing them in there and um if it fails right so in here if it fails we also don't care if it fails or not right so we also kind of ignore that fact uh right so let me let me see does it compile so we need to wrap that in parenthesis thank you compil it very much uh not found in the scope ooh okay so new message must contain not only the bytes but also the alter so one cool thing that uh I use in Rust quite often is enumerations that also structures so essentially I can do things like this right so this is the bytes and this is the Alor which is also Arc this thing uh all right and it makes it a little bit easier to to padr match things like that right because then I can do uh outer bytes and I can just like use them directly right because they're correspondent fields in here so I might as well even um turn that into these things so this is the author uh like so and this is althor as well and porting the pon matches to like a new kind of thing is super easy you just replace the parenthesis with Cur braces and it's basically the same right it's basically the same that's actually very very useful very cool can your go do that go doesn't even have a PO matching uh right okay let's try to compile that it created even more errors okay so eer is not a method of not found for Arc client s client s there we go uh and here no okay so this is because that so we have to do as ref uhhuh and uh okay so this is cool um who is the reference who is the reference I suppose can I just do EQ not right because expected this and this is like this right so it will actually compare like values right it will actually compare the values if I understand correctly right so uh let me find the method EQ um so it's actually part of the point it's kind of dangerous yeah we have to be super careful so this is a value and this is a pointer so to be 100% sure let's just do it like that right let's just do it like that so we have to be super careful but I mean uh I I think rust in this particular case won't allow you to shoot your leg so um I don't think it's that big of a deal oh it cannot find the method right because I removed it the the rust warnings and um so and here we want to do that by a reference and here when we send in a message right when we're send in a message yeah we have to do it like that so this is the althor right so now it is like this uh and here when we disconnect now it is like this can you by the way see shut okay auor uh like this there go and this one is a little bit interesting because this one is bytes that we're sending this is the bytes that we're sending and this is the author uh which is a stream clone I wonder if constantly cloning that reference is too expensive it probably is it probably is but it compiles and you know what's funny is that we basically translated the functionality of the server without the uh you know message rate limits and Al Banning so the functionality is translated one to one using the same architecture the architecture of a single several threat and several client threats and like you you know a single consumer mul multiple Publishers so this entire thing is basically translated so and this is precisely why I decided that like to try it out because again as I already said rust has pretty much the same sort of like Paradigm Primitives um but we haven't tested it yet of course we haven't tested it yet but it already compiles and as you know as they say in the industry if it compiles chat say the line Chad say the line if it [Music] compiles it works yay anyway so let's give it a try let's see if it's true or not I don't know look at that uh can I now uh do a T net on this thing hello uh we can't really see anything so uh let's try to maybe uh connect to another one uh right so let's let's actually put it like this so you can see everything so let's do tell net 2701 6969 hello what the hello how are you doing smiley face I'm doing fine thank you so first try by the way uh so how do I quit this so and I never worked like never worked with that API before right I never with this API before so and I just like managed to leun it right on the screen and on the Stream So and the functionality has been like literally ported right so one to one uh and I just translated the code so the only thing we're missing is the strike system right so and stuff like that uh how can you still dislike rust because I think it's too much effort for what I wanted in here honestly it's very bureaucratic especially when it comes to uh just sharing a reference between the threats you may argue that it is intentional because it's a very dangerous thing and it's very easy to shoot your leg but uh I don't like how rust prioritizes safety too much over convenience and ergonomics of the language right so essentially um there's two things like ergonomics and like is to use of the language and the safety safety is important but what Ras does is that safety completely ignoring ergonomics like ergonomics right so completely it out of the window and that's what annoys me like can we optimize both can we optimize both safety and ergonomics and stuff like that but if I feel like it's kind of difficult to pull off in a current uh rust Community because rust Community is just like there's too much discussion going on in Rust Community because quite often for a simple sort of feature there could be thousand and thousand and thousand upon thousand comments discussing red hoing over like an important thing and going nowhere and it's kind of like H I don't know sometimes I feel like rust lacks a coherent Vision if that makes any sense you know what I'm talking about it's just like their vision is just safety at all cost right just safety at all cost and that's the entire vision and and it's just constant fighting and drama and stuff like that so quite often I know projects that maybe rust needs like a benivolent benevolent dictator if you know what I'm talking about so if you take a look at the project with benevolent dictators they usually have like a very clear coherent Vision right clear CER Vision even though sometimes some people might be uh not happy with this kind of stuff but at least there is a coherent Vision python 2 maybe I'm saying that because I'm authoritarian that's why so this is the my authoritarian part of me is speaking right now right so yes project needs to have a benevolent dictator yes I know what I'm talking about not authoritarian whatsoever so why are you so authoritarian that's a good question actually sometimes I do feel that I am a little bit authoritarian say that in the Russian but you if you don't speak Russian you won't understand that or like do you speak Russian I don't know I didn't speak Russian it's very difficult English um okay so let's go ahead and Deport the uh you know the rate limit system and the out Banning system and stuff like that I'm losing my voice by the way but it is what it is and it is what it is do do we have time by the way way uh and I'm not talking about like the real time time in um right in Rust we do have time there is STD time and do we have okay so there must be something like time now there is so there's a Time instant now so what is the instant um so let me read about an instant a measure of monotonically non ah okay so it's basically a clock right right it's a clock for maybe per performance me measure something like that uh right so uh so we probably need to use a system time right but to be fair if it's a temporary ban right if it's a temporary ban maybe would they need a system time whatever let's let's use a system time yep clock um system time there we go so let's open the go Implement Implement struct where is the client so stract uh client so there's a connection uh last message right so we need to have last message and uh system time right so and we're also going to have um I don't remember do we have to comput common in here but the compiler will tell me whatever strike count so this is a strike count cool uh so yesu yesu yesu so we also need to introduce a thing called band MFS right so that's very important so we have band MFS band mother focus band mother focus um okay so can I split it slightly differently yeah so the first thing we do in here we take the address of the author right so here it is this is an address which which is kind of cool and uh we have band MFS band MFS we need to check uh we need to get uh you know the thing when they were banned banned at uh well I mean we have to find a method in hash map that gets a value right and it usually it returns an option indicating that it might be missing right it indicates it's that it might be missing uh so and here we have like this is a very convenient way of doing that so now I have to do a completely different way of working with this kind of thing H I know that hashmap had a take I think it had a take hashmap take so actually take uh accepts a value right removes and Returns the value it's a hash set though but I wanted hashmap hashmap take yeah well it doesn't have a take okay whatever so the problem is that it's not really um it's not really easy to translate the go code to whatever we have in here but that's fine I suppose uh althor addr althor addr uh and in here we're going to have the band at but that band at is essentially option but maybe that's fine actually maybe that's actually fine we can't translate that because we can yeah we can use band at as band at and band simultaneously we can do that we actually can do that that's very cool because now uh so essentially if let some uh band at Bend at that's what we do uh so we also keep track of the now which is basically system time now right now and if so there is some sort of a sub subtraction system system time uh so do you have sub you do have sub so basically rust and go they stealing from each other so who stole from whom who stole that idea from whom I don't freaking know so and apparently you can probably use a minus separator we could try a minus separator why not uh so and essentially we do now minus that and uh so that gives us o this one is rather interesting [Music] so this is a t um but it accepts the duration o we need a difference actually uh can we have like a difference we can't have difference uh so STD time STD time so we need a difference somehow duration from milliseconds so there should be something like sces I'm pretty sure system time like sces duration scenes Yeah Boy uh that's what I'm talking and it could be are you freaking serious well I mean if it's okay I see what's going on [Music] here so Returns the amount of time elapsed from the earlier point of time okay so you take that uh new duration since all right so um band at uh but maybe so we have to actually follow it slightly differently so I mean name it's different band at so this is a newer one and you use newer one duration duration since now right duration since now um yeah duration SS baned at because it's a numeron and they basically assert the clock may have gone backwards so if the clock may have B gun backwards what do we do how do we even handle that because that could be something that could be sort of like an attack if an attacker gained some sort of like a control over the clock they could set the clock and crash the entire server I feel like we shouldn't crash in here uh right so I feel like we shouldn't crash in here but yeah who knows uh expect to do don't crash if the clock uh went backwards because right now I just don't really want to bother handling all of that uh right so and uh duration uh so we got some sort of duration so that's cool uh duration so what we can do with the duration can we compare the duration uh so I it probably implements ordered interface does it Implement ordered interface it does implement audit interface how can I construct this kind of thing can I construct it from seconds I can in fact con construct it from seconds uh actually F32 this is perfect actually this is actually perfect um so I can even maybe have uh something like Global and it's not even a constant thing so you can't have like a global constant in here uh like you would do in go uh right so because we have band limit in there right so we have band limit um yeah so we could introduce const ban limit then say duration uh this is the duration from sex is it uh yeah they also call it sex nice one F32 and band limit is basically 10 * 60 so it's basically 10 seconds uh right you can't have that because it's rust because you this is rust uh right so can you have something like that in the current stable rust or is it not nightly fish uh I'm not even sure so because I I feel like it has to be like a con thingy but this one is not const um right so we just have Pub FN so there's nothing constant here so probably we can't have that even though that would have been super useful uh that would have been a super a super useful okay so what do we have in here so uh this is a strike count this has to be let's put it i32 what else do we have in here canot find because this is the author address uh and um so integer okay so this ah why did you remove everything why did you remove everything uh band okay so you want a reference what else do you want uh expected system okay so this is not what I thought it is uh excuse me so I suppose it just out okay it doesn't know the return type yikes okay freaking so there is also a lapsed time but whatever I mean we're already moving in that direction um so and for it to know all of these types I have to explicitly say them and unless I finish like it's very annoying that I have to okay so but I mean I have no other choice uh TCP Stream So if I remember correctly we are using na uh nap in there right so this is going to be peer address so this is a socket address but not really uh socket address V6 right and we have IP in here and it's IPv6 is there something like just a General IP so if I just okay so there's a generic IP IP address okay that's very cool is it hashable is it it is hashable okay so that means uh I can just do IP address IP addr and the value is system time so that's cool uh and in here we can maybe even also explicitly say soet ADR uh client so that's pretty cool um so IP IDR so iddr all right so let's go through the compilation uh so expected um so socket ADR okay so that means we need to take the IP uhhuh what else do we want uh so finally so now we uh inferred all of the necessary types O So band at is a reference now is not a reference so that means I have to get Now by a reference can I just der reference this thing then um okay so I I managed to do that cool cool uh so last uh last message and strike okay last message is going to be system uh time we can just put now in there and the strike count is going to be zero all right okay so uh I think we're done and uh cannot call non constant and what's funny is that I probably won't be able to even do something like that in here as well right because you can't uh F 32s are not you can have them as constants look at that you can have F32 as constants duration from sex is const uh really let's let's take a look let's take a look at the sex uh duration from sex duration from sex it is con would you look at that wow wow w uh all right duration uh duration from sex uh but I mean I want to me mate but I want a fractional part disappointed anyways uh okay so duration since and we've got this kind of thing that's good that's cool uh and if the duration is um basically greater or equal depends on how we even do that ban limit greater or equal to uh ban limit right we actually delete that band from this thing and I'm pretty sure we won't be able to easily do that because of this kind of I'm pretty sure we won't be able to easily do that I really doubt that though though we could try to map it we could try to do and then or something like that so we can do it like that so okay it's mutable band at and we um do then or maybe and then right so in in here we get band at uh all right and inside of this thing this is what we do and essentially if it's greater than that entire thing if it's greater than that entire thing we uh basically return none right we basically return none and that effectively so that single return none acts like effectively setting it to false and maybe potentially deleting but we'll get to that a little bit later we'll get to that a little bit later otherwise if it's not we're just keeping the band at as it is so we just keeping it as it is uh right and what's interesting is that so we could do a very interesting thing so people say that there is a remove method in hash map right so which effectively just takes it out of there uh and everything so that could be that could be useful uh right so you accept that so we're taking this thing out of the hash map we taking it out of the hash map uh and then we continue so then later on then later on if we're still bent we'll put it back into the band MFS that is very actually cool uh so that works out kind of well so if let uh some Bend at right we can even maybe we can even do something like this if band at is sum uh we probably want to answer uh you're ban you're ban that's what we want to say right so that's basically what we want to say you ban and we want to close the connection otherwise we want to do something like so here we want to do is none uh we simply would do it like that and it's translated almost exactly as it was in go Isn't that cool uh right so if it's not none right if it's not none we want to put it back M so and to put it back it would be just easier to do it like let some band at band at uh Bend uh MFS um insert uh insert author addr I so we're just like literally P putting it back band at and this one goes here but we also have to say something to the to the author right so we also have to say something to the author uh althor um as ref and we want to write something to them we want to write something to them but it's writable thing so that means we should be able to do something like write a L uh like so and we can say uh you are band MF you're ban you're ban uh so and in here so maybe we don't want to D reference it too often right so I can do something like alter like this so then I can just use it like that and then alter um can I explicitly close this entire thing is that something I can do right if I have a TCP string can I explicitly close it um I didn't think so I want to be able to explicitly close it but I don't feel like I can uh so people say that I probably need to drop it like it's hot but I don't feel like it's um okay so I can I can try to do drop so I know that drop is like a destructors of rust so that uh yeah yeah so okay we can try that and see how it goes we can try but it's probably it has to be mutable right so it has to be mutable you can't really easily drop that uh you can't easily drop that MFS is it going to like like that small little thing is going to us over really really hard uh so okay so band at uh we don't have to do that anymore right so we don't really have to do that anymore uh band at expected yeah it has to be some so that's understandable and in here expect it just okay so uhhuh you want a copy of this thing sure I can give you a copy all right and drop you can't just easily drop that method not found at TCP stream that's understandable uh shut down okay so we can give it a try TCP stream uh shut down sounds good why did they call it shut down that's such a well I mean it's actually kind of a common term for for this kind of thing okay so let's just let's just call shutdown thank you thank you so much so this is a shutdown and it may or may not return something so in this case we're going to just do expect uh I probably just don't want to even care about it right so just like shut it down so what does it say an argument shut down is missing what do we want how shut down okay that's very interesting Poss they can be uh the reading portion of TCP okay let's do both down both mm it doesn't know that it's part of the net mhm shut down has to be uh this thing doesn't have to be mutable sure um and uh auor o it has to be mutable by the way it has to be because I'm basically reassigning it back probably you can simplify this entire thing but I mean who cares cannot borrow as [Music] mutable so what does it suggest just add mutable okay well that Sol it I thought we'll never get out of that maze but we managed to do that holy what the we manage to crawl out of that Labyrinth of borrow checking bullsh holy f for a second I thought we're going to die we're going to get lost in this lab because of this kind of situation but yeah luckily there is a shutdown in here oh boy holy okay uh you can definitely simplify this is just not obvious yeah I'm pretty sure but I'm I'm basically translating go code to rust one to one and that's be that's why it's kind of weird like that um right so yeah let's yes yes yes okay the disconnect is implemented correctly right so well we forgot one little thing we forgot one little thing we forgot to say how much sex you have left so that's very important uh sex uh right so uh sex left so when the question is what is sex um so basically take the band limits right so we take the band limit and we are subtracting the band at right so we do have band at so that's totally fine so here yeah this one is very interesting because we basically moved it inside so we we will probably have to reorder some but that's fine um so we we take the difference between these two things and um and both of them are duration uh can I now take the duration and translate it to seconds duration [Music] right two sex so there is as sex F32 we need a sex F32 all right so that's cool we can do it like that as sex F32 as sex F32 okay so uh expected um so expect because this is duration what mismatch type duration oh it's a system typ really band at is a system type um wait what I'm confused a little bit oh yeah you take that difference again you take that difference again uh but that difference only makes sense okay mhm whatever uh so we can probably call it diff diff and uh so okay uh we're good to go so uh that is very AOG that is very aous um so disconnect is implemented correctly so that's totally fine so now we need to implement this one monstrosity of the situation this monstrosity of the situation uh okay good so now uh what do we do we need to take the author address so we've got the author address so then we need to find the author uh right so let's do author um clients um clients get author add DDR author a DDR and we also need now uh let now so this is kind of important so this is a let now so we first need to check that author still exists within the clients because essentially you can have a situation when uh the client is already disconnected or banned or something like that but there are messages there are still messages from them in the que right there are still messages from them in q and uh you basically want to protol them to be fair to be fair um maybe new message should actually yeah things like client disconnected and new messages should not directly accept TCP streams and stuff like that they probably should not uh what they should do instead they should accept IPS right so they should accept IPS maybe this is something that we have to uh I think that's a generally good idea right so yes yes yes so because we're going to be uh querying those things from there anyway right we're going to be quering them from there anyway and by the way because of that maybe you have disconnects from things that don't really exist anymore but it's quite unlikely it's quite unlikely so uh so we need to have a socket address right so this is the alter uh socket ad R and this one is a socket edor as well socket edor so let's go to the compilation errors and just sort of Port that a little bit uh just Port that a little bit uhuh so what we have here so uh author addr all right so this is author addr we don't have to do that anymore but we can get the althor and now if uh let hm we can even inline this entire thing if let some Alor Alor addr maybe we don't even need to do well but we'll see we'll see so this one goes here and yeah so that works out hopefully so new message outter ADR does not have a field author addr aha so what's called aldr then so that's totally fine so alter DDR so that is fine Alor ADR okay that even should have done that earlier should have done that earlier that's that's very cool that's very cool uh all right so alter addr so that's that means we're on the right track um so and okay so this doesn't have to be the that that gets rid of the CL by the way right so P HDR hopefully that's something we can do maybe we have to do azf as um so res oh it could be so it may fail uh right it may fail so we removed that code yeah yeah okay so we removed that code so one of the things we probably want to do we want to do author addr right author addr author I think that's how you pronounce that right author HDR I'm sure if you need this thing but anyway so expect uh to do cache the pier uh address right so because we're going to be doing that on each sort of fre I think it will make sense to cat this entire thing uh right and the same goes in here so we can just do it once I'm pretty sure we can just do it once and here just do auor addr and then simply btes we can Factor this stuff out like so am I even an considered an epic Ruster now am I an epic rooster now look at that look how easily I factor out outside the loop yeah that's actually cool idea yo yeah and yeah that's a that's a good idea so we essentially if you can't do that if you can't do that we can even crash the client right away yo okay so that sols even more problems than I expected okay print L error could not get perer address uh of well whatever uh error something like that yo yo that is absolutely POG boogers uh so what uh what's up with that so auth author is not even used anymore so that's expected what else do we have last message is not used uh unused result so that's fine anything else we have last message and strike count I guess we're Gucci I guess we are in fact taguchi so we have this situation when uh you may not have some clients in there uh so now uh what can we do then we have to calculate how much time has passed since the last message of the user right uh nice uh lost message yes lost message uh so yeah I'm just thinking why there is no semicolons in here this is go actually this is actually go um all right so now we need to find the difference again for some reason finding the difference is a little bit painful uh right because you have to do this kind of thing but uh we can now copy paste things right uh but in here uh we don't have to do band at we have to do uh author um last last last message right so author last message uh and if the difference is greater or equal than message rate message rate only then we would allow we would authorize that specific message but only then we're authorizing that uh and a message rate is basically a duration rate message rate uh duration from sex it's going to be 1 second M duration from sex so flushed and that's basically so we can go to the compilation right just to see if okay so the only thing that is left in here now is is a strike count uh this is because we are striking the user around in here right so somewhere here uh and how do we strike the user first of all we increment their strike all right oh and incrementing their strike will require to to modify them right so we take author strike count we just incremented by one and here we get it as immutable so that means we have to get it as mutable that makes sense but here comes another interesting thing if author author strike count is greater or equal than the strike limit the time has come to ban this MF the time has come to ban this MF uh [Music] so mm but that also well yeah we don't have to modify the map so everything's fine I thought that we'll have to uh remove the connection from the map we don't have to do that it could be done later from the client disconnected so that's totally fine uh so what do we do we add that to the list of band MFS by the way maybe it would be better to actually put go at the bottom uh band MFS uh we in insert we insert author addr IP and we clone this entire thing and what we put in there we put now right then we take an auor connection all right an autho connection and we just write yeah we just write your band MF you are band MF H where do we get author so when it's connected we we just do it like that um so I'm thinking is that can we write a len and then say you are baned MF like so very dramatically very dramatically and then we shut down this entire thing like so we shut down both of these met flippers like so uh so uh let me see so you're ban M and then we shut it down so that means it will be removed later will be removed later okay so let's go through compilation uh strike limit is not uh implemented so this is going to be just like 10 if I remember correctly that's that's just 10 cannot borrow as mutable cannot borrow as mutable so can we do just a as ref uh as uhhuh yo look at that we managed to do that so but we don't check whether sequence of bites that we're sending is uh valid utf8 we don't check for that right so this is something that main goal should do as well right so it it does that uh too so as you can see it just validates that thing so what we can do uh we can do from UTF uh we go and that does validation for us so that's that's very cool um so this is going to be rust and within this thing we just take the bites right we just take the bus and we're just constructing I'm surprised St Str from utf8 right so strr from utf8 if let um some text we're going to be just sending that text there uh I wonder if I can simply write that text like so well I mean the compiler will tell me if I'm doing something wrong but whatever so otherwise we're just striking that user just striking that user so and banning them okay so what does it say uh no function sayate from ETF in the uh that is surprising to me because isn't that part of Sr or is that because I never imported okay so SD Sr yeah that makes sense uh okay so this is a reference that's fine what else do we have in here uh okay so yeah this expression has type result oh okay so this is okay uhhuh I'm not going to probably log that uh okay so it doesn't like that so you cannot just write that string one of the things we can do we can do write Ln uh this thing as a ref and just write that text just squish that cat simply squish that guom I think we fully translated this mother fer Str strr has bytes so it's kind of funny so we are translating it to Str strr just to to just to validate that it's cf8 and then we're going to be taking bytes out of that Str Str to write them we could do that uh we could do that but that's kind of funny you can reuse the bites that's a good point that's a good point so what if I okay let's actually go back that's that's funny huh bite so right because we validated them uhhuh can I do that or is it going to be huh that's a very interesting way of doing that is there something validate is valid utf8 so utf8 because it's kind of weird honestly is there a not valid HF some kind of function uh yeah like I don't know that would makes sense to me but if it's not is that how rust developers uh you can do is okay sure that's that's also fine uh right so you can do is okay uh all right I just can't believe that that is it we managed to translate this entire thing so yesu yesu yesu um I don't know if I want to do the DS test right now um right so I think I'm going to just test it locally um and then we'll see 6969 hello uh we can't really see shed but that's that's fine uh so tell uh hello all right that's cool uh so I want to actually do something like close and let's try to Doos this thing we're going to cat def Ur random and uh nc1 uh 6969 h I didn't get banned though uh that's that's funny though H so why didn't I get banned why didn't I get banned because I would expect it to tell me at least at least you're ban yeah so we probably use a lot of let in here uh maybe we we should actually uh like log some info in here uh we can do ePrint L could not send band message to uh do we have the Alor addr yeah we do have Alor addr um Alor PDR error so let's actually put as many errors as possible um right so when we do shut down it may also fail um map error so this one has to be map error though okay error could not shut down socet for author addr because of the error that's understandable so let me try to compile so what does it say um yeah so it's you still need to do it like that right because we're ignoring these things uh what's the other stuff so map error and E print LM eror could not write right uh could not broadcast message to all the clients uh from Alor addr because of this specific error all right so I want to also specify where exactly okay all these things are happening uh could not uh could not send band message uhhuh shut down all right and this is we can copy paste this entire thing mhm CU it's literally the same mhm so we are ignoring this entire thing we could probably do map error in here um so could broadcast could not uh e l er um could uh the server could not send uh client okay so we could probably copy paste this thing yeah who said we can't do that um so in this case we just don't care right we just simply don't care because we're already like recovering from the f fail situation anyway so it just doesn't matter at this point anymore and that's basically it I feel like all right okay hello honestly I think I need to also log different situations uh when somebody connected and stuff like that you know when somebody connected and stuff like that so maybe uh I could just steal some stuff from here yeah so for example somebody connected where is that thing yeah so here uh ePrint Ln um in for client uh alterr connected so it's actually the doesn't have to be like this but you then we can say client disconnected so this is disconnected and uh in here so we just don't do anything here so we're skipping all of these things I don't think it makes sense to even log that um we can basically yeah let's just log it like this print L info client uh a client author HDR send message oh and here text would have been useful actually text would have been useful so that's actually kind of funny so if let uh okay text because we're printing it like that so text would more useful that's cool um so and when we striking somebody uh it would make sense to also do that uh to also look that uh Ino client author address uh got B right and we're doing it like that l in a loot of like as much as possible as much as possible all right looks good to me looks Gucci looks even to maguchi would even say uh all right so boom client has connected hello uh sent message hello did I put uh Slash uh sln somewhere no I didn't oh sln comes from the from the sln in here when I pressed it in here God damn it so maybe maybe I should print the bytes then yeah let's print the bytes then in this case uh so what does it say uh mhm what oh okay so we can just do the debugs one right so it could be de one how did they deog one I don't remember so I think it's the other way around yeah it's the other way around uh okay so boom test all right so this is the bites and everything okay so client blah blah blah connect it and then we can close the connection ooh got it I think I know what's going on I think I think I think I know how to fix this um so if okay end of file if n is equal Z okay n equals z there we go greater than zero so I'm going to do a very dumb thing otherwise just you know um so let me let me see uh read uh read read read it's um a read One MH pull some bites blah blah blah this function oh the return so if the return value of this method okay an implementation must guarantee that a non zero n value indicates that the buffer has been filled with n bytes then it indicates one one of two scenarios the reader has reach the end of file and likely longer be able to produce bites know that this does not mean that the reader will always no longer be able to produce bites for un synchronous situations right so that's understandable the buffer specified was Zero bytes in length Okay um so that is cool that is cool um so error uh reached um so we can say that auor client uh author addr uh reached reached the uh end of file yeah and we sending that sh in there and something like that okay so that's cool uh that's cool that's cool I think we figured it out so actually loging everything was useful right so we managed to figure it out okay uh close okay this sing l or maybe break okay so yeah uh because that would break out of all of these things automatically because of the question mark uh right [Music] so all right all right all right all right so okay so that means we probably also want to do something something like this because it returns result that's understandable yeah that's cool so before we yeah we never actually got out of that Loop so that's that's kind of funny uh yeah finally so maybe loging reached and the file is not particularly useful uh reached and the file so I'm not going do that uh okay so we do that and close disconnect it hello test epic epic epic so now uh close and see boom uh you bam you bam it's broken some pipes uh could not send uh band message oh did I actually send the band message could not send because we shut down uh that's really funny H oh yeah because we were maybe receiving some stuff from okay I I can see that being being a thing right so I can see that being a thing but it's not that big of a deal uh so then I can try to connect uh all right okay so you banned m m uh in this seconds okay that's cool um so we probably need to log something your ban MF um this is uh how much left it will be nice to just say something like uh info client so we already say client connect yeah yeah so we say client connected in here client uh uh ADR tried to connect but that MF is banned for sex sex um know what I'm going to extract the sex out of it like so there we go s okay so what the is that uh right so NC boom okay so we try to connect and uh try to connect but dat MF is banned for this amount of seconds okay so that's that's cool try to connect but that m is banned for this amount of seconds uh so and then we can do that hello world test isn't that epic is that epic so we can try to Doos that uh we we could try to do do that um I probably I think logging stuff as just bytes is fine right so because it basically automatically screens any racist n n uh it also automatically reduces possibility of Escape sequences or something like that so that's actually good so I'm not going to be looking um showing on the screen anything like super sensitive but you as a client when you connect be aware that some people may send some sensitive stuff like racist or n and I absolutely do not approve that this is just like nature of this entire thing and I haven't implemented any authentication to without some other people so connect to that server on your own risk so so we're we're on the same page on that right so everything's fine connect to that on your own risk so if you're scared of scary hackers uh so do not connect there but to be fair I don't think they will be able to do something super scary right because like again like there's no possibility of Escape sequences or anything we literally validate utfa and stuff like that leak IP IP is the Same by the way as usual so actually I just reinstalled the same machine um are you printing oh we also yeah yeah we need to screen the sensitive data thank you for imagining oh this will require to to do lot right this will require to do a lot of work but what if I deploy on um uh I feel like Escape sequences are valid utf8 ah all right so let's not do do not do do now what's not noos for today so uh yeah all right so we roll this in Rust uh surprisingly it worked fine right so uh we have this thing working fine uh so and uh yeah so that's it for today thanks everyone who's watching me right now I really appreciate that have a good one and I see all on the next recreational programming session with Ain love you all
Info
Channel: Tsoding Daily
Views: 88,870
Rating: undefined out of 5
Keywords:
Id: BbIEuNscn_E
Channel Id: undefined
Length: 158min 21sec (9501 seconds)
Published: Sat Nov 04 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.