Skip to content

Missing code in Server file #9

@duarteoctavio

Description

@duarteoctavio

Missing code section in Server

It seems at some point a section of code was omitted "to be done", but never got added.
Obiously, the content of the Ok() block is the serve function defined in the same file, but I would like to see how you had implemented it.

Thanks for writing this interesting book!

Relevant code: Line 43 to 67 in the complete_blockchain/src/server.rs file.

    pub fn run(&self, addr: &str) {
        let listener = TcpListener::bind(addr).unwrap();

        if addr.eq(CENTERAL_NODE) == false {
            let best_height = self.blockchain.get_best_height();
            send_version(CENTERAL_NODE, best_height);
        }
        for stream in listener.incoming() {
            let blockchain = self.blockchain.clone();
            thread::spawn(|| match stream {
                Ok(stream) => {
                    ...
                }
                Err(e) => {
                    ...
                }
            });
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions