GithubHelp home page GithubHelp logo

go-utp's Introduction

Go μTP

GoDoc

Go implementation of the Micro Transport Protocol.

Getting Started

First you will need a net.PacketConn. This can be anything implementing the interface. There are no abstraction-breaking checks for a particular implementation. Then use utp.NewSocket to get started.

func createSocket() *utp.Socket {
    // Create a UDP socket listening on all addresses
    pc, err := net.ListenPacket("udp", "0.0.0.0:0")
    if err != nil {
        panic(err)
    }

    // Call utp.New to create a *utp.Socket from the net.PacketConn
    s := utp.NewSocket(pc)
    return s
}

// As a server
func useAsServer(s *utp.Socket) error {
    for {
        conn, err := s.Accept()
        go func() {
            defer conn.Close()
            // handle the conn
        }
    }
}

// As a client
func useAsClient(s *utp.Socket, raddr net.Addr) error {
    conn, err := s.DialContext(ctx, raddr)
    if err != nil {
        return err
    }
    defer conn.Close
    // send some data to the other party
    _, err := conn.Write([]byte("hello world"))
    return err
}

Instrumentation

All logging and metrics are provided by the stdctx library. If you want logs or metrics just configure a context as described there, and pass it in.

Contributing

just is used to run commands.

just test runs the tests.

Contributions are welcome.

Roadmap

Long term it would be best for the implementation to change to be more testable. The Socket and Conn objects are the right API (adhearing to net.Listener/net.Dialer and net.Conn respectively), but they are difficult to test. There needs to be a state machine object, which doesn't have go routines or timers internally, so that arbitrary stimulus at arbitrary states can be tested.

Fork

Orginally forked from github.com/anacrolix/utp. There were a number of reasons for forking:

  • The pure go implementation is deprecated in favor of a C-Go port of libutp. This fork will continue to be pure Go.
  • The API was very UDP specifc, taking string addresses in several places.
  • Legacy logging, and instrumentation.
  • High quality user experience on top of INET256.

go-utp's People

Contributors

anacrolix avatar brendoncarroll avatar prettymuchbryce avatar mjgarton avatar tsuzu avatar vtolstov avatar

Stargazers

GITSRC avatar Anatol avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.