Beispiel #1
0
func NewSocks4AuthenticationResponse(result byte, port v2net.Port, ip []byte) *Socks4AuthenticationResponse {
	return &Socks4AuthenticationResponse{
		result: result,
		port:   port.Value(),
		ip:     ip,
	}
}
Beispiel #2
0
func writeSocks4Response(writer io.Writer, errCode byte, address v2net.Address, port v2net.Port) error {
	buffer := buf.NewLocal(32)
	buffer.AppendBytes(0x00, errCode)
	buffer.AppendSupplier(serial.WriteUint16(port.Value()))
	buffer.Append(address.IP())
	_, err := writer.Write(buffer.Bytes())
	return err
}
Beispiel #3
0
func (v *Assert) Port(value net.Port) *PortSubject {
	return &PortSubject{
		Subject: Subject{
			a:    v,
			disp: value.String(),
		},
		value: value,
	}
}
Beispiel #4
0
func (this *Assert) Port(value v2net.Port) *PortSubject {
	return &PortSubject{
		Subject: Subject{
			a:    this,
			disp: value.String(),
		},
		value: value,
	}
}
Beispiel #5
0
func appendAddress(buffer *buf.Buffer, address v2net.Address, port v2net.Port) {
	switch address.Family() {
	case v2net.AddressFamilyIPv4:
		buffer.AppendBytes(0x01)
		buffer.Append(address.IP())
	case v2net.AddressFamilyIPv6:
		buffer.AppendBytes(0x04)
		buffer.Append(address.IP())
	case v2net.AddressFamilyDomain:
		buffer.AppendBytes(0x03, byte(len(address.Domain())))
		buffer.AppendSupplier(serial.WriteString(address.Domain()))
	}
	buffer.AppendSupplier(serial.WriteUint16(port.Value()))
}
Beispiel #6
0
func (subject *PortSubject) LessThan(expectation net.Port) {
	if subject.value.Value() >= expectation.Value() {
		subject.Fail("is less than", expectation.String())
	}
}
Beispiel #7
0
func (subject *PortSubject) GreaterThan(expectation net.Port) {
	if subject.value.Value() <= expectation.Value() {
		subject.Fail("is greater than", expectation.String())
	}
}
Beispiel #8
0
func (subject *PortSubject) Equals(expectation net.Port) {
	if subject.value.Value() != expectation.Value() {
		subject.Fail("is equal to", expectation.String())
	}
}
Beispiel #9
0
func (wsl *WSListener) listenws(address v2net.Address, port v2net.Port) error {
	http.HandleFunc("/"+wsl.config.Path, func(w http.ResponseWriter, r *http.Request) {
		con, err := wsl.converttovws(w, r)
		if err != nil {
			log.Warning("WebSocket|Listener: Failed to convert connection: ", err)
			return
		}

		select {
		case wsl.awaitingConns <- &ConnectionWithError{
			conn: con,
		}:
		default:
			if con != nil {
				con.Close()
			}
		}
		return
	})

	errchan := make(chan error)

	listenerfunc := func() error {
		ol, err := net.Listen("tcp", address.String()+":"+strconv.Itoa(int(port.Value())))
		if err != nil {
			return err
		}
		wsl.listener, err = NewStoppableListener(ol)
		if err != nil {
			return err
		}
		return http.Serve(wsl.listener, nil)
	}

	if wsl.tlsConfig != nil {
		listenerfunc = func() error {
			var err error
			wsl.listener, err = getstopableTLSlistener(wsl.tlsConfig, address.String()+":"+strconv.Itoa(int(port.Value())))
			if err != nil {
				return err
			}
			return http.Serve(wsl.listener, nil)
		}
	}

	go func() {
		err := listenerfunc()
		errchan <- err
		return
	}()

	var err error
	select {
	case err = <-errchan:
	case <-time.After(time.Second * 2):
		//Should this listen fail after 2 sec, it could gone untracked.
	}

	if err != nil {
		log.Error("WebSocket|Listener: Failed to serve: ", err)
	}

	return err

}